Computer Math

21
Computer Math CPS120: Data Representation

description

Computer Math. CPS120: Data Representation. Representing Data. The computer knows the type of data stored in a particular location from the context in which the data are being used; i.e. individual bytes, a word, a longword, etc 01100011 01100101 01000100 01000000 - PowerPoint PPT Presentation

Transcript of Computer Math

Page 1: Computer Math

Computer Math

CPS120: Data Representation

Page 2: Computer Math

Representing Data

• The computer knows the type of data stored in a particular location from the context in which the data are being used; – i.e. individual bytes, a word, a longword, etc– 01100011 01100101 01000100 01000000

• Bytes: 99(10, 101 (10, 68 (10, 64(10

• Two byte words: 24,445 (10 and 17,472 (10

• Longword: 1,667,580,992 (10

Page 3: Computer Math

2

Natural NumbersZero and any number obtained by repeatedly adding one to it.

Examples: 100, 0, 45645, 32

Negative NumbersA value less than 0, with a – sign

Examples: -24, -1, -45645, -32

Numbers

Page 4: Computer Math

3

IntegersA natural number, a negative number, zero

Examples: 249, 0, - 45645, - 32

Rational NumbersAn integer or the quotient of two integers

Examples: -249, -1, 0, ¼ , - ½

Numbers (Cont’d)

Page 5: Computer Math

4

How many ones are there in 642?

600 + 40 + 2 ?

Or is it

384 + 32 + 2 ? -- Octal

Or maybe…

1536 + 64 + 2 ? -- Hexadecimal

Natural Numbers

Page 6: Computer Math

5

642 is 600 + 40 + 2 in BASE 10

The base of a number determines the number of digits and the value of digit positions

Natural Numbers

Page 7: Computer Math

6

Continuing with our example…642 in base 10 positional notation is:

6 x 10² = 6 x 100 = 600

+ 4 x 10¹ = 4 x 10 = 40 + 2 x 10º = 2 x 1 = 2 = 642 in base 10

This number is in base 10

The power indicates the position of

the number

Positional Notation

Page 8: Computer Math

7

 dn * Rn-1 + dn-1 * R

n-2 + ... + d2 * R + d1

As a formula:

642 is:  63 * 102 +  42 * 10 +  21

R is the base of the number

n is the number of digits in the number

d is the digit in the ith position

in the number

Positional Notation

Page 9: Computer Math

68

What if 642 has the base of 13?

642 in base 13 is equivalent to 1068 in base 10

+ 6 x 13² = 6 x 169 = 1014 + 4 x 13¹ = 4 x 13 = 52 + 2 x 13º = 2 x 1 = 2

= 1068 in base 10

Positional Notation

Page 10: Computer Math

Representing Real Numbers

• Real numbers have a whole part and a fractional part. For example 104.32, 0.999999, 357.0, and 3.14159 the digits represent values according to their position, and those position values are relative to the base.

• The positions to the right of the decimal point are the tenths position (10-1 or one tenth), the hundredths position (10-2 or one hundredth), etc.

Page 11: Computer Math

Representing Real Numbers (Cont’d)

• In binary, the same rules apply but the base value is 2. Since we are not working in base 10, the decimal point is referred to as a radix point.

• The positions to the right of the radix point in binary are the halves position (2-1 or one half), the quarters position (2-2 or one quarter), etc.

Page 12: Computer Math

Representing Real Numbers (Cont’d)

• A real value in base 10 can be defined by the following formula:

• The representation is called floating point because the number of digits is fixed but the radix point floats.

Page 13: Computer Math

Representing Real Numbers (Cont’d)

• Likewise, a binary floating –point value is defined by the following formula:sign * mantissa * 2exp

Page 14: Computer Math

Representing Real Numbers (Cont’d)

• Scientific notation is a term with which you may already be familiar, so we mention it here. Scientific notation is a form of floating-point representation in which the decimal point is kept to the right of the leftmost digit.

• For example, 12001.32708 would be written as 1.200132708E+4 in scientific notation.

Page 15: Computer Math

Representing Text

• To represent a text document in digital form, we simply need to be able to represent every possible character that may appear.

• There are finite number of characters to represent. So the general approach for representing characters is to list them all and assign each a binary string.

• A character set is simply a list of characters and the codes used to represent each one. By agreeing to use a particular character set, computer manufacturers have made the processing of text data easier.

Page 16: Computer Math

Alphanumeric Codes

• American Standard Code for Information Interchange (ASCII)– 7-bit code– Since the unit of storage is a bit, all ASCII codes are

represented by 8 bits, with a zero in the most significant digit– H e l l o W o r l d– 48 65 6C 6C 6F 20 57 6F 72 6C 64

• Extended Binary Coded Decimal Interchange Code (EBCDIC)

Page 17: Computer Math

The ASCII Character Set

• ASCII stands for American Standard Code for Information Interchange. The ASCII character set originally used seven bits to represent each character, allowing for 128 unique characters.

• Later ASCII evolved so that all eight bits were used which allows for 256 characters.

Page 18: Computer Math

The ASCII Character Set (Cont’d)

Page 19: Computer Math

The ASCII Character Set (Cont’d)

• Note that the first 32 characters in the ASCII character chart do not have a simple character representation that you could print to the screen.

Page 20: Computer Math

The Unicode Character Set

• The extended version of the ASCII character set is not enough for international use.

• The Unicode character set uses 16 bits per character. Therefore, the Unicode character set can represent 216, or over 65 thousand, characters.

• Unicode was designed to be a superset of ASCII. That is, the first 256 characters in the Unicode character set correspond exactly to the extended ASCII character set.

Page 21: Computer Math

The Unicode Character Set (Cont’d)

A few characters in the Unicode character set