Number Systems and Data Representation CS221 word decimal

Number Systems and Data Representation CS221

Inside today's computers, data is represented as 1's and 0's. These 1's and 0's might be stored magnetically on a disk, or as a state in a transistor, core, or vacuum tube. To perform useful operations on these 1's and 0's we have to organize them together into patterns that make up codes. First we will discuss numeric values for the codes, and then ways that the codes represent textual values.

Each 1 and 0 is called a bit. 4 bits is called a nibble. 8 bits is called a byte. 16/32/64/128 bits is called a word. The number depends upon the number of bits that can simultaneously be operated upon by the processor. Most processors today use 32 bits.

Since we only have 1's and 0's available, the number system generally used inside the computer is the binary number system. We are used to the decimal number system. In decimal, we have ten symbols (0-9) that we can use. When all of the symbols are used up, we need to combine together two symbols to represent the next number (10). The most significant digit becomes our first digit, and the least significant digit cycles back to 0. The least significant digit increments until the symbols are used up, and which point the most significant digit is incremented to the next larger digit. This is just the familiar process of counting!

The same process applies to the binary number system, but we only have two symbols available (0-1). When we run out of symbols, we need to combine them and increment the digits just as we would in a decimal, base 10, number system: Let's start counting to illustrate:

Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

Binary 0 1 10 11 100 101 110 111 1000 1001 1010 1011 1100 1101 1110 1111 ? ?

Binary to Decimal Conversion

The binary number system is positional where each binary digit has a weight based upon

its position relative to the least significant bit (LSB). To convert a binary number to

decimal, sum together the weights. Each weight is calculated by multiplying the bit by 2i, where i is the index relative to the LSB.

1 0 0 1 1

24

23

22

21

20

Weight = 1*20 + 1*21 + 0*22 + 0*23 + 1*24

= 1*1 + 1*2 + 0*4 + 0*8 + 1*16

= 1+2+16 = 19 (base 10, decimal)

What is 1111 in base 10? What is 10101 in base 10?

Decimal to Binary Conversion

To convert a decimal number to its equivalent binary number representation, the easiest method is to use repeated division by 2. Each time, save the remainder. The first remainder is the least significant bit. The last remainder is the most significant bit.

What is 19 in binary?

19 / 2 = 9 9 / 2 = 4 4 / 2 = 2 2 / 2 = 1 1 / 2 = 0

remainder 1 remainder 1 remainder 0 remainder 0 remainder 1

LSB MSB

Our final number is 10011.

If using a calculator, watch to see if the quotient has a fraction. If it is 0.5 then the remainder was 1, and repeat the process with the whole part minus the fraction.

What is 83 in binary? What is 100 in binary?

Octal Numbers

The octal number system uses base 8 instead of base 10 or base 2. This is sometimes convenient since many computer operations are based on bytes (8 bits). In octal, we have 8 digits at our disposal, 0-7. Let's do the counting again:

Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

Octal 0 1 2 3 4 5 6 7 10 11 12 13 14 15 16 17 20

Octal to Decimal Conversion

Converting octal to decimal is just like converting binary to decimal, except instead of powers of 2, we use powers of 8. That is, the LSB is 80, the next is 81, then 82, etc.

To convert 172 in octal to decimal:

1 7 2

82

81

80

Weight = 2*80 + 7*81 + 1*82

= 2*1 + 7*8 + 1*64

= 122 base 10

What is 104 in octal converted to decimal? What is 381 in octal converted to decimal?

Decimal to Octal Conversion

Converting decimal to octal is just like converting decimal to binary, except instead of dividing by 2, we divide by 8. To convert 122 to octal:

122 / 8 = 15 15 / 8 = 1 1 / 8 = 0

remainder 2 remainder 7 remainder 1 = 172 octal

If using a calculator to perform the divisions, the result will include a decimal fraction instead of a remainder. The remainder can be obtained by multiplying the decimal fraction by 8. For example, 122 / 8 = 15.25. Then multiply 0.25 * 8 to get a remainder of 2.

Octal to Binary, Binary to Octal

Octal becomes very useful in converting to binary, because it is quite simple. The conversion can be done by looking at 3 bit combinations, and then concatenating them together. Here is the equivalent for each individual octal digit and binary representation:

Octal 1 2 3 4 5 6 7

Binary 001 010 011 100 101 110 111

To convert back and forth between octal and binary, simply substitute the proper pattern for each octal digit with the corresponding three binary digits.

For example, 372 in octal becomes 010 111 010 or 010111010 in binary. 777 in octal becomes 111 111 111 or 111111111 in binary.

The same applies in the other direction:

100111010 in binary becomes 100 111 010 or 472 in octal.

What is 441 octal in binary? What is 10110 binary in octal?

Since it is so easy to convert back and forth between octal and binary, octal is sometimes used to represent binary codes. Octal is most useful if the binary code happens to be a multiple of 3 bits long. Sometimes it is quicker to convert decimal to binary by first converting decimal to octal, and then octal to binary.

Hexadecimal Numbering

The hexadecimal numbering system is the most common system seen today in representing raw computer data. This is because it is very convenient to represent groups of 4 bits. Consequently, one byte (8 bits) can be represented by two groups of four bits easily in hexadecimal.

Hexadecimal uses a base 16 numbering system. This means that we have 16 symbols to use for digits. Consequently, we must invent new digits beyond 9. The digits used in hex are the letters A,B,C,D,E, and F. If we start counting, we get the table below:

Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

Hexadecimal 0 1 2 3 4 5 6 7 8 9 A B C D E F 10 11 ...

Binary 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 10000 10001

Hex to Decimal Conversion

Converting hex to decimal is just like converting binary to decimal, except instead of powers of 2, we use powers of 16. That is, the LSB is 160, the next is 161, then 162, etc.

To convert 15E in hex to decimal:

1 5 E 162 161 160 Weight = 14*160 + 5*161 + 1*162

= 14*1 + 5*16 + 1*256

= 350 base 10

What is F00 in hex converted to decimal?

Decimal to Hex Conversion

Converting decimal to hex is just like converting decimal to binary, except instead of dividing by 2, we divide by 16. To convert 350 to hex:

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download