Top-Rated Free Essay
Preview

Number System Tutorial

Powerful Essays
8000 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Number System Tutorial
NUMBER SYSTEMS TUTORIAL

Courtesy of: thevbprogrammer.com

Number Systems

Number Systems Concepts
The study of number systems is useful to the student of computing due to the fact that number systems other than the familiar decimal (base 10) number system are used in the computer field. Digital computers internally use the binary (base 2) number system to represent data and perform arithmetic calculations. The binary number system is very efficient for computers, but not for humans. Representing even relatively small numbers with the binary system requires working with long strings of ones and zeroes. The hexadecimal (base 16) number system (often called "hex" for short) provides us with a shorthand method of working with binary numbers. One digit in hex corresponds to four binary digits (bits), so the internal representation of one byte can be represented either by eight binary digits or two hexadecimal digits. Less commonly used is the octal (base 8) number system, where one digit in octal corresponds to three binary digits (bits). In the event that a computer user (programmer, operator, end user, etc.) needs to examine a display of the internal representation of computer data (such a display is called a "dump"), viewing the data in a "shorthand" representation (such as hex or octal) is less tedious than viewing the data in binary representation. The binary, hexadecimal , and octal number systems will be looked at in the following pages. The decimal number system that we are all familiar with is a positional number system. The actual number of symbols used in a positional number system depends on its base (also called the radix). The highest numerical symbol always has a value of one less than the base. The decimal number system has a base of 10, so the numeral with the highest value is 9; the octal number system has a base of 8, so the numeral with the highest value is 7, the binary number system has a base of 2, so the numeral with the highest value is 1, etc. Any number can be represented by arranging symbols in specific positions. You know that in the decimal number system, the successive positions to the left of the decimal point represent units (ones), tens, hundreds, thousands, etc. Put another way, each position represents a specific power of base 10. For example, the decimal number 1,275 (written 1,27510)* can be expanded as follows: 1 2 7 510 5 7 2 1 x x x x 100 101 102 103 = = = = 5 7 2 1 x x x x 1 10 100 1000 = = = = 5 70 200 1000 -----1275

10

Remember the mathematical rule that n0 = 1, or any number raised to the zero power is equal to 1. Here is another example of an expanded decimal number: 1 0 4 0 610 6 0 4 0 1 x x x x x 100 101 102 103 104 = = = = = 6 0 4 0 1 x x x x x 1 10 100 1000 10000 = 6 = 0 = 400 = 0 = 10000 -------10406

10

* When doing number system problems, it is helpful to use a subscript to indicate the base of the number being worked with. Thus, the subscript "10" in 127510 indicates that we are working with the number 1275 in base 10. Page 2

Number Systems

TRY THIS: Expand the following decimal number: 5 1 3 010

The Binary Number System
The same principles of positional number systems we applied to the decimal number system can be applied to the binary number system. However, the base of the binary number system is two, so each position of the binary number represents a successive power of two. From right to left, the successive positions of the binary number are weighted 1, 2, 4, 8, 16, 32, 64, etc. A list of the first several powers of 2 follows: 20 = 1 26 = 64 21 = 2 27 = 128 22 = 4 28 = 256 23 = 8 29 = 512 24 = 16 210 = 1024 25 = 32 211 = 2048

For reference, the following table shows the decimal numbers 0 through 31 with their binary equivalents: Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Binary 0 1 10 11 100 101 110 111 1000 1001 1010 1011 1100 1101 1110 1111 Decimal 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Binary 10000 10001 10010 10011 10100 10101 10110 10111 11000 11001 11010 11011 11100 11101 11110 11111

Page 3

Number Systems

Converting a Binary Number to a Decimal Number To determine the value of a binary number (10012, for example), we can expand the number using the positional weights as follows: 1 0 0 12 1 0 0 1 x x x x 20 21 22 23 = = = = 1 0 0 1 x x x x 1 2 4 8 = = = = 1 0 0 8 -----9

10

Here's another example to determine the value of the binary number 11010102: 1 1 0 1 0 1 02 0 1 0 1 0 1 1 x x x x x x x 20 21 22 23 24 25 26 = = = = = = = 0 1 0 1 0 1 1 x x x x x x x 1 2 4 8 16 32 64 = = = = = = = 0 2 0 8 0 32 64 -----106

10

TRY THIS: (a) 1

Convert the following binary numbers to their decimal equivalents: 1 0 0 1 1 02

(b)

1

1

1

1

1

0

0

12

Page 4

Number Systems

Converting a Decimal Number to a Binary Number To convert a decimal number to its binary equivalent, the remainder method can be used. (This method can be used to convert a decimal number into any other base.) The remainder method involves the following four steps: (1) (2) (3) (4) Divide the decimal number by the base (in the case of binary, divide by 2). Indicate the remainder to the right. Continue dividing into each quotient (and indicating the remainder) until the divide operation produces a zero quotient. The base 2 number is the numeric remainder reading from the last division to the first (if you start at the bottom, the answer will read from top to bottom).

Example 1: Convert the decimal number 9910 to its binary equivalent:

0 2 1

1

(7)

Divide 2 into 1. The quotient is 0 with a remainder of 1, as indicated. Since the quotient is 0, stop here.

1 2 3

1

(6)

Divide 2 into 3. The quotient is 1 with a remainder of 1, as indicated.

3 2 6

0

(5)

Divide 2 into 6. The quotient is 3 with a remainder of 0, as indicated.

6 2 12

0

(4)

Divide 2 into 12. The quotient is 6 with a remainder of 0, as indicated.

12 2 24

0

(3)

Divide 2 into 24. The quotient is 12 with a remainder of 0, as indicated

24 2 49

1

(2)

Divide 2 into 49 (the quotient from the previous division). The quotient is 24 with a remainder of 1, indicated on the right.

49 START HERE ⇒ 2 99

1

(1)

Divide 2 into 99. The quotient is 49 with a remainder of 1; indicate the 1 on the right.

The answer, reading the remainders from top to bottom, is 1100011, so 9910 = 11000112.

Page 5

Number Systems

Example 2: Convert the decimal number 1310 to its binary equivalent:

0 2 1

1

(4)

Divide 2 into 1. The quotient is 0 with a remainder of 1, as indicated.

1 2 3

1

(3)

Divide 2 into 3. The quotient is 1 with a remainder of 1, as indicated.

3 2 6

0

(2)

Divide 2 into 6. The quotient is 3 with a remainder of 0, indicated on the right.

6 START HERE ⇒ 2 13

1

(1)

Divide 2 into 13. The quotient is 6 with a remainder of 1; indicate the 1 on the right.

The answer, reading the remainders from top to bottom, is 1101, so 1310 = 11012. TRY THIS: (a) Convert the following decimal numbers to their binary equivalents: 4910 (b) 2110

Page 6

Number Systems

Binary Addition Adding two binary numbers together is easy, keeping in mind the following four addition rules: (1) (2) (3) (4) 0 0 1 1 + + + + 0 1 0 1 = = = = 0 1 1 10

Note in the last example that it was necessary to "carry the 1". After the first two binary counting numbers, 0 and 1, all of the binary digits are used up. In the decimal system, we used up all the digits after the tenth counting number, 9. The same method is used in both systems to come up with the next number: place a zero in the "ones" position and start over again with one in the next position on the left. In the decimal system, this gives ten, or 10. In binary, it gives 102, which is read "one-zero, base two."

Consider the following binary addition problems and note where it is necessary to carry the 1:

1

1

1

1

1

1

1

+

1 0 1

1 0 1

0 1 1

+ 1

1 1 0

1 0 1

+ 1

1 1 0

0 0 0

0 1 1

+ 1

1 0 0

1 1 0

+ 1

1 0 0

0 1 0

1 1 0

0 1 1

+ 1

1 0 0

1 1 1

1 0 0

1 1 1

1 1 0

TRY THIS: (a) + 1 1 0 1 0 0

Perform the following binary additions: 1 0 (b) + 1 1 1 1 1 0 0 1 (c) + 1 0 0 0 1 1 0 1 1 1 (d) + 1 1 1 1 0 1 1 0 1 1 0 1

Subtraction Using Complements Subtraction in any number system can be accomplished through the use of complements. A complement is a number that is used to represent the negative of a given number. When two numbers are to be subtracted, the subtrahend* can either be subtracted directly from the minuend (as we are used to doing in decimal subtraction) or, the complement of the subtrahend can be added to the minuend to obtain the difference. When the latter method is used, the addition will produce a high-order (leftmost) one in the result (a "carry"), which must be dropped. This is how the computer performs subtraction: it is very efficient for the computer to use the same "add" circuitry to do both addition and subtraction; thus, when the computer "subtracts", it is really adding the complement of the subtrahend to the minuend.

* In mathematical terminology, the factors of a subtraction problem are named as follows: Minuend - Subtrahend = Difference. Page 7

Number Systems

To understand complements, consider a mechanical register, such as a car mileage indicator, being rotated backwards. A five-digit register approaching and passing through zero would read as follows: 00005 00004 00003 00002 00001 00000 99999 99998 99997 etc. It should be clear that the number 99998 corresponds to -2. Furthermore, if we add 00005 + 99998 1 00003 and ignore the carry to the left, we have effectively formed the operation of subtraction: 5 - 2 = 3. The number 99998 is called the ten's complement of 2. The ten's complement of any decimal number may be formed by subtracting each digit of the number from 9, then adding 1 to the least significant digit of the number formed. In the example above, subtraction with the use of complements was accomplished as follows: (1) We were dealing with a five-digit subtrahend that had a value of 00002. First, each digit of the subtrahend was subtracted from 9 (this preliminary value is called the nine's complement of the subtrahend): 9 0 9 (2) 9 0 9 9 0 9 9 0 9 9 2 7

Next, 1 was added to the nine's complement of the subtrahend (99997) giving the ten's complement of subtrahend (99998): 9 9 9 9 + 9 7 1 8

9

9

9

(3)

The ten's complement of the subtrahend was added to the minuend giving 100003. The leading (carried) 1 was dropped, effectively performing the subtraction of 00005 - 00002 = 00003. + 1 0 9 0 0 9 0 0 9 0 0 9 0 5 8 3

The answer can be checked by making sure that 2 + 3 = 5.

Page 8

Number Systems

Another example: Still sticking with the familiar decimal system, subtract 4589 - 322, using complements ("eyeballing" it tells us we should get 4267 as the difference). (1) First, we'll compute the four digit nine's complement of the subtrahend 0322 (we must add the leading zero in front of the subtrahend to make it the same size as the minuend): 9 0 9 (2) 9 3 6 9 2 7 9 2 7

Add 1 to the nine's complement of the subtrahend (9677) giving the ten's complement of subtrahend (9678): 9 6 7 + 7 7 1 8

9

6

(3)

Add the ten's complement of the subtrahend to the minuend giving 14267. Drop the leading 1, effectively performing the subtraction of 4589 - 0322 = 4267. + 1 4 9 4 5 6 2 8 7 6 9 8 7

The answer can be checked by making sure that 322 + 4267 = 4589. TRY THIS: (a) Solve the following subtraction problems using the complement method:

5086 - 2993 =

(b)

8391 - 255 =

Page 9

Number Systems

Binary Subtraction We will use the complement method to perform subtraction in binary and in the sections on octal and hexadecimal that follow. As mentioned in the previous section, the use of complemented binary numbers makes it possible for the computer to add or subtract numbers using only circuitry for addition - the computer performs the subtraction of A - B by adding A + (two's complement of B) and then dropping the carried 1. The steps for subtracting two binary numbers are as follows: (1) Compute the one's complement of the subtrahend by subtracting each digit of the subtrahend by 1. A shortcut for doing this is to simply reverse each digit of the subtrahend - the 1's become 0's and the 0's become 1's. Add 1 to the one's complement of the subtrahend to get the two's complement of the subtrahend. Add the two's complement of the subtrahend to the minuend and drop the high-order 1. This is your difference.

(2) (3)

Example 1: Compute 110101012 - 10010112 (1) Compute the one's complement of 10010112 by subtracting each digit from 1 (note that a leading zero was added to the 7digit subtrahend to make it the same size as the 8-digit minuend): 1 0 1 1 1 0 1 0 1 1 0 1 1 1 0 1 0 1 1 1 0 1 1 0

-

-

-

-

-

-

-

-

(Note that the one's complement of the subtrahend causes each of the original digits to be reversed.) (2) Add 1 to the one's complement of the subtrahend, giving the two's complement of the subtrahend: 1 0 1 1 0 1 0 + 0 0 1 1

1 (3)

0

1

1

0

1

Add the two's complement of the subtrahend to the minuend and drop the high-order 1, giving the difference:
1 1 1 1 1

+ 1

1 1 1

1 0 0

0 1 0

1 1 0

0 0 1

1 1 0

0 0 1

1 1 0

So 110101012 - 10010112 = 100010102. The answer can be checked by making sure that 10010112 + 100010102 = 110101012 .

Page 10

Number Systems

Example 2: Compute 111110112 - 110000012 (1) Come up with the one's complement of the subtrahend, this time using the shortcut of reversing the digits: Original number: One's complement: 1 1 0 0 0 0 0 1 0 0 1 1 1 1 1 0

(2)

Add 1 to the one's complement of the subtrahend, giving the two's complement of the subtrahend (the leading zeroes of the one's complement can be dropped): 1 1 1 1 1 + 1 0 1 1

1 (3)

1

1

1

Add the two's complement of the subtrahend to the minuend and drop the high-order 1, giving the difference:
1 1 1 1 1 1 1

1

1 + 0

1 1 1

1 1 1

1 1 1

0 1 0

1 1 1

1 1 0

1

0

So 111110112 - 110000012 = 1110102. The answer can be checked by making sure that 110000012 + 1110102 = 111110112. TRY THIS: (a) Solve the following binary subtraction problems using the complement method: (b) 1001002 - 111012 =

110011012 - 101010102 =

Page 11

Number Systems

The Octal Number System
The same principles of positional number systems we applied to the decimal and binary number systems can be applied to the octal number system. However, the base of the octal number system is eight, so each position of the octal number represents a successive power of eight. From right to left, the successive positions of the octal number are weighted 1, 8, 64, 512, etc. A list of the first several powers of 8 follows: 80 = 1 81 = 8 82 = 64 83 = 512 84 = 4096 85 = 32768

For reference, the following table shows the decimal numbers 0 through 31 with their octal equivalents: Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Octal 0 1 2 3 4 5 6 7 10 11 12 13 14 15 16 17 Decimal 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Octal 20 21 22 23 24 25 26 27 30 31 32 33 34 35 36 37

Converting an Octal Number to a Decimal Number To determine the value of an octal number (3678, for example), we can expand the number using the positional weights as follows: 3 6 78 7 6 3 x x x 80 = 81 = 82 = 7 6 3 x x x 1 8 64 = = = 7 48 192 -----247

10

Here's another example to determine the value of the octal number 16018: 1 6 0 18 1 0 6 1 x x x x 80 81 82 83 = = = = 1 0 6 1 x x x x 1 8 64 512 = = = = 1 0 384 512 -----897

10

Page 12

Number Systems

TRY THIS: (a) 5

Convert the following octal numbers to their decimal equivalents: 3 68

(b)

1

1

6

38

Converting a Decimal Number to an Octal Number To convert a decimal number to its octal equivalent, the remainder method (the same method used in converting a decimal number to its binary equivalent) can be used. To review, the remainder method involves the following four steps: (1) (2) (3) (4) Divide the decimal number by the base (in the case of octal, divide by 8). Indicate the remainder to the right. Continue dividing into each quotient (and indicating the remainder) until the divide operation produces a zero quotient. The base 8 number is the numeric remainder reading from the last division to the first (if you start at the bottom, the answer will read from top to bottom).

Example 1: Convert the decimal number 46510 to its octal equivalent: 0 8 7 7 (3) Divide 8 into 7. The quotient is 0 with a remainder of 7, as indicated. Since the quotient is 0, stop here.

7 8 58

2

(2)

Divide 8 into 58 (the quotient from the previous division). The quotient is 7 with a remainder of 2, indicated on the right.

58 START HERE ⇒ 8 465

1

(1)

Divide 8 into 465. The quotient is 58 with a remainder of 1; indicate the 1 on the right.

The answer, reading the remainders from top to bottom, is 721, so 46510 = 7218.

Page 13

Number Systems

Example 2: Convert the decimal number 254810 to its octal equivalent: 0 8 4 4 (4) Divide 8 into 4. The quotient is 0 with a remainder of 4, as indicated. Since the quotient is 0, stop here.

4 8 39

7

(3)

Divide 8 into 39. The quotient is 4 with a remainder of 7, indicated on the right.

39 8 318

6

(2)

Divide 8 into 318 (the quotient from the previous division). quotient is 39 with a remainder of 6, indicated on the right.

The

318 START HERE ⇒ 8 2548

4

(1)

Divide 8 into 2548. The quotient is 318 with a remainder of 4; indicate the 4 on the right.

The answer, reading the remainders from top to bottom, is 4764, so 254810 = 47648. TRY THIS: (a) 300210 Convert the following decimal numbers to their octal equivalents: (b) 651210

Page 14

Number Systems

Octal Addition Octal addition is performed just like decimal addition, except that if a column of two addends produces a sum greater than 7, you must subtract 8 from the result, put down that result, and carry the 1. Remember that there are no such digits as "8" and "9" in the octal system, and that 810 = 108 , 910 = 118, etc.

Example 1: Add 5438 + 1218 (no carry required): 5 1 6 4 2 6 3 1 4

+

Example 2: Add 76528 + 45748 (carries required):
1 1

+

7 4
12 - 8 = 4

6 5
12 - 8 = 4

5 7
12 - 8 = 4

2 4

1

4

4

4

6

TRY THIS: (a) +

Perform the following octal additions: 5 3 4 2 3 4 0 1 (b) + 6 1 4 2 0 3 5 4

Page 15

Number Systems

Octal Subtraction We will use the complement method to perform octal subtraction. The steps for subtracting two octal numbers are as follows: (1) (2) (3) Compute the seven's complement of the subtrahend by subtracting each digit of the subtrahend by 7. Add 1 to the seven's complement of the subtrahend to get the eight's complement of the subtrahend. Add the eight's complement of the subtrahend to the minuend and drop the high-order 1. This is your difference.

Example 1: Compute 75268 - 31428 (1) Compute the seven's complement of 31428 by subtracting each digit from 7: 7 3 4 (2) 7 1 6 7 4 3 7 2 5

-

-

-

-

Add 1 to the seven's complement of the subtrahend, giving the eight's complement of the subtrahend: 4 6 3 + 3 5 1 6

4 (3)

6

Add the eight's complement of the subtrahend to the minuend and drop the high-order 1, giving the difference:
1 1

+

7 4
12 - 8 = 4

5 6
11 - 8 = 3

2 3

6 6
12 - 8 = 4

1 So 75268 - 31428 = 43648

4

3

6

4

The answer can be checked by making sure that 31428 + 43648 = 75268 .

Page 16

Number Systems

Example 2: Compute 5458 - 148 (1) Compute the seven's complement of 148 (putting in a leading zero to make it a three-digit number) by subtracting each digit from 7: 7 0 7 7 1 6 7 4 3

-

-

-

(2) Add 1 to the seven's complement of the subtrahend, giving the eight's complement of the subtrahend: 7 6 + 6 3 1 4

7

(3) Add the eight's complement of the subtrahend to the minuend and drop the high-order 1, giving the difference:
1 1

+

5 7
13 - 8 = 5

4 6
11 - 8 = 3

5 4
9-8=1

1 So 5458 - 148 = 5318

5

3

1

The answer can be checked by making sure that 148 + 5318 = 5458 . TRY THIS: (a) Solve the following octal subtraction problems using the complement method: (b) 54348 - 35568 =

67768 - 43378 =

Page 17

Number Systems

The Hexadecimal Number System
The hexadecimal (base 16) number system is a positional number system as are the decimal number system and the binary number system. Recall that in any positional number system, regardless of the base, the highest numerical symbol always has a value of one less than the base. Furthermore, one and only one symbol must ever be used to represent a value in any position of the number. For number systems with a base of 10 or less, a combination of Arabic numerals can be used to represent any value in that number system. The decimal number system uses the Arabic numerals 0 through 9; the binary number system uses the Arabic numerals 0 and 1; the octal number system uses the Arabic numerals 0 through 7; and any other number system with a base less than 10 would use the Arabic numerals from 0 to one less than the base of that number system. However, if the base of the number system is greater than 10, more than 10 symbols are needed to represent all of the possible positional values in that number system. The hexadecimal number system uses not only the Arabic numerals 0 through 9, but also uses the letters A, B, C, D, E, and F to represent the equivalent of 1010 through 1510, respectively. For reference, the following table shows the decimal numbers 0 through 31 with their hexadecimal equivalents: Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Hexadecimal 0 1 2 3 4 5 6 7 8 9 A B C D E F Decimal 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Hexadecimal 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F

The same principles of positional number systems we applied to the decimal, binary, and octal number systems can be applied to the hexadecimal number system. However, the base of the hexadecimal number system is 16, so each position of the hexadecimal number represents a successive power of 16. From right to left, the successive positions of the hexadecimal number are weighted 1, 16, 256, 4096, 65536, etc.: 160 = 1 161 = 16 162 = 256 163 = 4096 164 = 65536

Page 18

Number Systems

Converting a Hexadecimal Number to a Decimal Number We can use the same method that we used to convert binary numbers and octal numbers to decimal numbers to convert a hexadecimal number to a decimal number, keeping in mind that we are now dealing with base 16. From right to left, we multiply each digit of the hexadecimal number by the value of 16 raised to successive powers, starting with the zero power, then sum the results of the multiplications. Remember that if one of the digits of the hexadecimal number happens to be a letter A through F, then the corresponding value of 10 through 15 must be used in the multiplication. Example 1: Convert the hexadecimal number 20B316 to its decimal equivalent. 2 0 B 316 3 11 0 2 x x x x 160 161 162 163 = = = = 3 11 0 2 x x x x 1 16 256 4096 = = = = 3 176 0 8192 -----8371

10

Example 2: Convert the hexadecimal number 12AE516 to its decimal equivalent. 1 2 A E 516 5 14 10 2 1 x x x x x 160 161 162 163 164 = = = = = 5 14 10 2 1 x 1 x 16 x 256 x 4096 x 65536 = 5 = 224 = 2560 = 8192 = 65536 -------76517

10

TRY THIS. (a)

Convert the following hexadecimal numbers to their decimal equivalents: 2 4 3 F16

(b)

B

E

E

F16

Page 19

Number Systems

Converting a Decimal Number to a Hexadecimal Number To convert a decimal number to its hexadecimal equivalent, the remainder method (the same method used in converting a decimal number to its binary equivalent) can be used. To review, the remainder method involves the following four steps: (1) (2) (3) (4) Divide the decimal number by the base (in the case of hexadecimal, divide by 16). Indicate the remainder to the right. If the remainder is between 10 and 15, indicate the corresponding hex digit A through F. Continue dividing into each quotient (and indicating the remainder) until the divide operation produces a zero quotient. The base 16 number is the numeric remainder reading from the last division to the first (if you start at the bottom, the answer will read from top to bottom).

Example 1: Convert 926310 to its hexadecimal equivalent:

0 16 2

2

(4)

Divide 16 into 2. The quotient is 0 with a remainder of 2, as indicated. Since the quotient is 0, stop here.

2 16 36

4

(3)

Divide 16 into 36. The quotient is 2 with a remainder of 4, indicated on the right.

36 16 578

2

(2)

Divide 16 into 578 (the quotient from the previous division). quotient is 36 with a remainder of 2, indicated on the right.

The

578 START HERE ⇒ 16 9263

F

(1)

Divide 16 into 9263. The quotient is 578 with a remainder of 15; so indicate the hex equivalent, "F", on the right.

The answer, reading the remainders from top to bottom, is 242F, so 926310 = 242F16.

Page 20

Number Systems

Example 2: Convert 425910 to its hexadecimal equivalent:

0 16 1

1

(4)

Divide 16 into 1. The quotient is 0 with a remainder of 1, as indicated. Since the quotient is 0, stop here.

1 16 16

0

(3)

Divide 16 into 16. The quotient is 1 with a remainder of 0, indicated on the right.

16 16 266

A

(2)

Divide 16 into 266 (the quotient from the previous division). The quotient is 16 with a remainder of 10, so the hex equivalent "A" is indicated on the right.

266 START HERE ⇒ 16 4259

3

(1)

Divide 16 into 4259. The quotient is 266 with a remainder of 3; so indicate 3 on the right.

The answer, reading the remainders from top to bottom, is 10A3, so 425910 = 10A316. TRY THIS: (a) 6949810 Convert the following decimal numbers to their hexadecimal equivalents: (b) 11426710

Page 21

Number Systems

Hexadecimal Addition One consideration is that if the result of an addition is between 10 and 15, the corresponding letter A through F must be written in the result: + 1 3 4 9 1 A 5 9 E

In the example above, 5 + 9 = 14, so an "E" was written in that position; 9 + 1 = 10, so an "A" was written in that position. A second consideration is that if either of the addends contains a letter A through F, convert the letter to its decimal equivalent (either by memory or by writing it down) and then proceed with the addition: 3 + 4 A
10

2 C
12

1

7

B

E

A third consideration is that if the result of an addition is greater than 15, you must subtract 16 from the result of that addition, put down the difference of that subtraction for that position, and carry a 1 over to the next position, as shown below:
1

D
13

E
14

B
11

+

1

0

E
14 11 + 14 = 25 25 - 16 = 9

E

F

9

In the example above, when B16 (1110) was added to E16 (1410), the result was 2510. Since 2510 is greater than 1510, we subtracted 1610 from the 2510 to get 910. We put the 9 down and carried the 1 over to the next position. Here is another example with carries:
1 1

8 + D
13 1 + 8+ 13 = 22 22- 16 = 6

F
15

9 4

7 C
12 7 + 12 = 19 19 - 16 = 3

5
15 + 5 = 20 20 - 16 = 4

1

6

4

E

3

Page 22

Number Systems

TRY THIS: (a) +

Perform the following hexadecimal additions: B 2 E A D 9 (b) + D B E E A E D F

Hexadecimal Subtraction We will use the complement method to perform hexadecimal subtraction. The steps for subtracting two hexadecimal numbers are as follows: (1) (2) (3) Compute the 15's complement of the subtrahend by subtracting each digit of the subtrahend by 15. Add 1 to the 15's complement of the subtrahend to get the 16's complement of the subtrahend. Add the 16's complement of the subtrahend to the minuend and drop the high-order 1. This is your difference.

Example 1: Compute ABED16 - 1FAD16 (1) Compute the 15's complement of 1FAD16 by subtracting each digit from 15: 15 1 E (2) 15 F 0 15 A 5 15 D 2

-

-

-

-

Add 1 to the 15's complement of the subtrahend, giving the 16's complement of the subtrahend: E 0 5 + 5 2 1 3

E (3)

0

Add the 16's complement of the subtrahend to the minuend and drop the high-order 1, giving the difference:
1 1 1

+

A E
24 - 16 = 8

B 0

E 5
20 - 16 = 4

D 3
16 - 16 = 0

1 So ABED16 - 1FAD16 = 8C4016

8

C

4

0

The answer can be checked by making sure that 1FAD16 + 8C4016 = ABED16.

Page 23

Number Systems

Example 2: Compute FEED16 - DAF316 (1) Compute the 15's complement of DAF316 by subtracting each digit from 15: 15 D 2 (2) 15 A 5 15 F 0 15 3 C

-

-

-

-

Add 1 to the 15's complement of the subtrahend, giving the 16's complement of the subtrahend: 2 5 0 + 0 C 1 D

2 (3)

5

Add the 16's complement of the subtrahend to the minuend and drop the high-order 1, giving the difference:
1 1 1

+

F 2
18 - 16 = 2

E 5
19 - 16 = 3

E 0

D D
26 - 16 = 10

1 So FEED16 - DAF316 = 23FA16

2

3

F

A

The answer can be checked by making sure that DAF316 + 23FA16 = FEED16. TRY THIS: (a) Solve the following hexadecimal subtraction problems using the complement method: (b) B6A116 - 8B1216 =

98AE16 - 1FEE16 =

Page 24

Number Systems

Converting Binary-to-Hexadecimal or Hexadecimal-to-Binary
Converting a binary number to its hexadecimal equivalent or vice-versa is a simple matter. Four binary digits are equivalent to one hexadecimal digit, as shown in the table below: Binary 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 Hexadecimal 0 1 2 3 4 5 6 7 8 9 A B C D E F

To convert from binary to hexadecimal, divide the binary number into groups of 4 digits starting on the right of the binary number. If the leftmost group has less than 4 bits, put in the necessary number of leading zeroes on the left. For each group of four bits, write the corresponding single hex digit. Example 1: Answer: 11010011011101112 = ?16 Bin: Hex: 1101 D 0011 3 0111 7 0111 7 Example 2: Answer: 1011011112 = ?16 Bin: Hex: 0001 1 0110 6 1111 F

To convert from hexadecimal to binary, write the corresponding group of four binary digits for each hex digit. Example 1: Answer: 1BE916 = ?2 Hex: Bin: 1 0001 B 1011 E 1110 9 1001 Example 2: Answer: B0A16 = ?2 Hex: Bin: B 1011 0 0000 A 1010

Page 25

Number Systems

Converting Binary-to-Octal or Octal-to-Binary
Converting a binary number to its octal equivalent or vice-versa is a simple matter. Three binary digits are equivalent to one octal digit, as shown in the table below: Binary 000 001 010 011 100 101 110 111 Octal 0 1 2 3 4 5 6 7

To convert from binary to octal, divide the binary number into groups of 3 digits starting on the right of the binary number. If the leftmost group has less than 3 bits, put in the necessary number of leading zeroes on the left. For each group of three bits, write the corresponding single octal digit. Example 1: Answer: 1101 0011011101112 = ?8 Bin: 001 101 001 Oct: 1 5 1 1011011112 = ?8 Bin: 101 101 Oct: 5 5

101 5

110 6

111 7

Example 2: Answer:

111 7

To convert from octal to binary, write the corresponding group of three binary digits for each octal digit. Example 1: Answer: 17648 = ?2 Oct: 1 Bin: 001 7318 = ?2 Oct: 7 Bin: 111 7 111 6 110 4 100

Example 2: Answer:

3 011

1 001

Page 26

Number Systems

Computer Character Sets and Data Representation
Each character is stored in the computer as a byte. Since a byte consists of eight bits, there are 28, or 256 possible combinations of bits within a byte, numbered from 0 to 255. There are two commonly used character sets that determine which particular pattern of bits will represent which character: ASCII (pronounced "as-key", stands for American Standard Code for Information Interchange) is used on most minicomputers and PCs, and EBCDIC (pronounced "eb-suh-dick", stands for Extended Binary Coded Decimal Interchange Code) is used on IBM mainframes. The ASCII Character Set (Characters 32 through 127) Shown below are characters 32 through 127 of the ASCII character set, which encompass the most commonly displayed characters (letters, numbers, and special characters). Characters 0 through 31 are used primarily as "control characters" (characters that control the way hardware devices, such as modems, printers, and keyboards work) - for example, character number 12 is the "form feed" character, which when sent to a printer, causes the printer to start a new page. Characters 128 through 255 are other special characters, such as symbols for foreign currency, Greek letters, and "box-drawing" characters that, for example, are used to make dialog boxes in DOS-text based (non-GUI) applications such as MS-DOS EDIT and QBASIC.

Decimal 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

Hex 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F

Char space ! " # $ % & ' ( ) * + , . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ?

Decimal 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95

Hex 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F

Char @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _

Decimal 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127

Hex 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F 70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F

Char ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~

Page 27

Number Systems

Data and instructions both "look" the same to the computer - they are both represented as strings of bits. The way a particular pattern of bits is treated by the computer depends on the context in which the string of bits is being used. For example, the bit pattern 000000001 (hex 01) can be interpreted by the computer in any of three ways: when it is interpreted as a machine language instruction, it causes the contents of two registers to be added together; when it is interpreted as a control code, it signifies a "start of heading" which precedes text in a data transmission; and when it is interpreted as a character (on IBM PCs), it shows up as a "happy face". And in addition to differentiating between instructions and data, there are different data types, or formats, which the computer treats in specific ways. In the ASCII character chart on the previous page, when the computer is using the bit patterns in a data "character" context, character 65 (hex 41 or binary 01000001) is treated as a capital "A". Likewise, when a data item such a zip code or phone number is stored, although it consists only of numeric digits, no arithmetic will be performed with that data item, so it is also suitable for being stored in "character" format. So a data item containing the zip code "90210" would be stored as (in hex) 3930323130. The computer cannot perform arithmetic on numeric quantities that are stored in character format. For example, if you wanted to add the number 125, the computer could not add it if it was stored as (hex) 313235. It would have to be stored as (or converted to) a numeric format that the computer can work with - either "integer" format or "floating point" format. In the pages that follow, we will look at how the computer stores various data items and how we can look at that internal representation via a memory "dump". The first order of business is to create some sample data. The following QBASIC program causes a file consisting of one record (consisting of fields of different data types) to be written to a file called "TESTFILE.DAT" and stored on disk: TYPE MyRecord MyName AS PosInt AS NegInt AS PosSing AS NegSing AS END TYPE STRING * 16 INTEGER INTEGER SINGLE SINGLE

This code here sets up a record structure with fields defined in various formats.

DIM TestRecord AS MyRecord OPEN "TESTFILE.DAT" FOR RANDOM AS #1 LEN = 28 TestRecord.MyName = "HARRY P. DODSON" TestRecord.PosInt = 25 TestRecord.NegInt = -2 TestRecord.PosSing = 6.75 TestRecord.NegSing = -4.5 PUT #1, , TestRecord CLOSE #1 END

Opens the DOS file into which the record data will be stored.

Fills the fields of the record with test data.

Writes a record to the file, closes the file, and ends the program.

The QBASIC program listed above defines a record 28 bytes long, with the fields mapped out as follows: A field called MyName, defined as STRING * 16. A STRING data type stores data in "character" format, using the ASCII characters as shown on the chart a couple of pages back. A field defined as STRING * n defines a character field n bytes long (16 bytes in this case). This then defines the first 16 bytes of the 28 byte record. The next two fields are INTEGER fields, called PosInt and NegInt. A QBASIC INTEGER field takes up two bytes of storage, so these two fields define the next 4 bytes of the record. Only integers, or whole numbers, can be stored in INTEGER type fields. INTEGER fields store values in "signed binary" format, where the high-order (leftmost) bit designates the sign of the number: a "zero" high-order bit signifies a positive number, a "one" high-order bit signifies a negative number.

Page 28

Number Systems

The bits of a positive integer field are arranged as you might expect: the value 5 would be stored as 00000000 00000101 (or 00 05 in hex). But a negative value is stored in two's complement notation - so the value -5 would be stored as 11111111 11111011 (or FF FB in hex). One more twist: the PC stores integer fields with the bytes arranged from right to left - NOT left to right as you might expect so the 5 in the example above would actually show up on a dump as 05 00 in hex, and the -5 would show up as FB FF in hex. The last two fields are defined as SINGLE fields, called PosSing and NegSing. A QBASIC SINGLE field takes up four bytes of storage, so these last two fields occupy the last eight bytes of the 28 byte record. SINGLE fields store numeric data in "floating point" format, which permits "real" numbers (numbers that can have digits after the decimal point) to be stored. Floating point format is the most complex data type to understand; it will be explained in the context of the data dump shown in the next section. Floating point fields are also stored with its bytes arranged from right to left. QBASIC has two other data types not used in this example. They are LONG and DOUBLE. LONG is a four-byte integer counterpart to the two-byte INTEGER data type, and DOUBLE is an eight-byte floating point counterpart to the four-byte SINGLE data type. After the sample QBASIC program was executed, a file called TESTFILE.DAT was created and placed in the default DOS directory. The file contained 28 bytes, for the storage of one record written out by the program. The contents of this file (or any file) can be "dumped" by the DOS DEBUG program. Below is a screen shot of that DOS session (the characters in bold represent the internal binary representation of the 28 bytes of the file, in hex): F:\CLC\CP110>debug testfile.dat -d 2F24:0100 48 41 52 52 59 20 50 2F24:0110 19 00 FE FF 00 00 D8 2F24:0120 00 DB D2 D3 E0 03 F0 2F24:0130 C0 16 F8 8E C2 AC 8A 2F24:0140 C2 24 FE 3C B0 75 05 2F24:0150 75 6D 6D 13 A8 01 50 2F24:0160 8E FC 12 A8 33 D2 29 2F24:0170 0B F8 83 FF FF 74 11 -q F:\CLC\CP110> The first line of the screen shot shows that the DEBUG program was initiated from the DOS prompt (the filename TESTFILE.DAT was supplied to the DEBUG command). When DEBUG runs, all you see is a "hyphen" prompt. At the hyphen, any one of a number of one-character commands can be given. On the second line of the screen shot, you see that the command "d" (for "dump") was given. This caused a section of memory to be dumped (as shown on the next several lines of the screen shot). The dump command caused the 28-byte file to be loaded into memory. The data from that file, along with whatever other "junk" was occupying the subsequent bytes of memory was displayed. After the section of memory was dumped, the hyphen prompt returned, where the "q" (for "quit") command was given. This caused the DEBUG program to end, causing the DOS prompt to return. The format of the DEBUG dump display is as follows: on the left of each line, the memory address (in hex) of the displayed data is given (in the screen shot above, the addresses are 2F24:0100, 2F24:0110, etc.). The main part of the line is the data being dumped, in hex format (16 bytes per line). The rightmost portion of each line is the ASCII character representation of the data being dumped; non-printable characters show up as dots (periods). The entire first line of the dumped data shows the hex representation of the content of the 16-byte field MyName (into which the QBASIC program had placed "HARRY P. DODSON"). You should see that the hex 48 corresponds to the letter "H", 41 corresponds to "A", 52 corresponds to "R, and so on. On the second line of the dumped data, the first two hex bytes are 19 00. This represents the value 25 that the QBASIC program placed in the INTEGER field PosInt. Recall that integer fields are stored with their bytes arranged from right to left, so we should read these two bytes as 00 19 - and you know that 1916 = 2510. The next two hex bytes on the second line of dumped data are FE FF. This represents the value -2 that the QBASIC program placed in the INTEGER field NegInt. Read as FF FE, you can see that this represents the two's complement of 2 (recall that negative Page 29

2E-20 40-00 8E-DA D0-00 AC-F3 14-74 E3-13 26-01

44 00 8B 00 AA B1 8B 1D

4F 90 C7 4E A0 BE C2 E2

44 C0 16 AD 0A 32 03 F3

53 34 C2 8B EB 01 C3 81

4F 00 B6 C8 06 8D 69 00

4E 13 01 46 3C 8B 02 94

20 2F 16 8A B2 1E 00 FA

HARRY P. DODSON .......@....4../ ................ ..........N...F. .$.

You May Also Find These Documents Helpful

  • Satisfactory Essays

    The range of values represented by an 8-bit binary number is _____. 4. The binary equivalent of 228 is _________. 5. The result of 7 – 2 using 1’s complement notation is 6.…

    • 4533 Words
    • 19 Pages
    Satisfactory Essays
  • Powerful Essays

    Nt1330 Unit 3 Assignment 1

    • 2019 Words
    • 9 Pages

    Subnetting IP Addressing • Internet Protocol (IP) • A unique indentifier for a host, or node, on an IP network • 32-bit binary number, usually expressed as 4 “dotted decimal” values. • Each decimal value represents 8 bits, in the range of 0 to 255 Example 140.179.220.200 140 Written in binary form: .179 .220 .200…

    • 2019 Words
    • 9 Pages
    Powerful Essays
  • Good Essays

    13.) What do you use to specify what bits are being used to lock a number into place?…

    • 641 Words
    • 3 Pages
    Good Essays
  • Better Essays

    Nt1310 Unit 1 Assignment

    • 1994 Words
    • 8 Pages

    * The binary numbering system plays a central role in how information of all kinds is stored on the computer. Understanding binary can lift a lot of the mysteries from computers because at a fundamental level they're really just machines for flipping binary digits on and off. There are several activities on binary numbers in this document, all simple enough that they can be used to teach the binary system to anyone who can count! Generally children learn the binary system very quickly using this approach, but we find that many adults are also excited when they finally understand what bits…

    • 1994 Words
    • 8 Pages
    Better Essays
  • Satisfactory Essays

    Number Conversions

    • 180 Words
    • 2 Pages

    2. Convert the hexadecimal number E7 into binary, and then convert the binary result into…

    • 180 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    3) Between -7999 and +7999. This is because 16 bits provide four four-bit locations. The lowest (right most) and two middle 4 bits can each store any number from 0 to 9. In the highest (left most) 4 bits, one bit is used for the sign, leaving 3 bits for digits. These 3 bits can accommodate numbers between 0 and 7.…

    • 1112 Words
    • 5 Pages
    Satisfactory Essays
  • Good Essays

    A user has opened a calculator application, typed the numbers 123456789, and then done some math problem using this number. Which of the following determines, in part, what bits the computer stores in RAM to represent the number 123456789?…

    • 605 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    Lab 1.4 ASCII

    • 349 Words
    • 3 Pages

    What is the ASCII hexadecimal code for a blank space? Why is it necessary to represent a blank space as a separate character in text? 32. Spaces are part of data.…

    • 349 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    IS3120 Unit 3

    • 650 Words
    • 2 Pages

    computer can transmit data in 1's and 0's on and off also called digital or binary form.…

    • 650 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Obviously, presenting data in this form would invite error. For this reason we use the hexadecimal (base 16) and, to a lesser extent, the octal (base 8) number systems.…

    • 412 Words
    • 4 Pages
    Good Essays
  • Powerful Essays

    27. Which of the following is a type of RAM that does not need to be refreshed?…

    • 475 Words
    • 2 Pages
    Powerful Essays
  • Powerful Essays

    For the hexadecimal main memory address 111111, 666666, BBBBBB, show the following information, in hexadecimal format:…

    • 1443 Words
    • 6 Pages
    Powerful Essays
  • Good Essays

    Analog Computers

    • 735 Words
    • 2 Pages

    The earliest computing machines in wide use were not digital but analog. In analog representation, properties of the representational medium ape (or reflect or model) properties of the represented state-of-affairs. (In obvious contrast, the strings of binary digits employed in digital representation do not represent by means of possessing some physical property — such as length — whose magnitude varies in proportion to the magnitude of the property that is being represented.) Analog representations form a diverse class. Some examples: the longer a line on a road map, the longer the road that the line represents; the greater the number of clear plastic squares in an architect's model, the greater the number of windows in the building represented; the higher the pitch of an acoustic depth meter, the shallower the water. In analog computers, numerical quantities are represented by, for example, the angle of rotation of a shaft or a difference in electrical potential. Thus the output voltage of the machine at a time might represent the momentary speed of the object being modelled.…

    • 735 Words
    • 2 Pages
    Good Essays
  • Good Essays

    Calculators History

    • 263 Words
    • 2 Pages

    Calculators also have the ability to store numbers into memory. Basic types of these store only one number at a time. More specific types are able to store many numbers represented in variables. The variables can also be used for constructing formulae. Some models have the ability to extend memory capacity to store more numbers; the extended address is referred to as an array index.…

    • 263 Words
    • 2 Pages
    Good Essays
  • Powerful Essays

    Numeral System

    • 2502 Words
    • 11 Pages

    In mathematics and computer science, the binary numeral system, or base-2 numeral system, represents numeric values using two symbols: 0 and 1. More specifically, the usual base-2 system is a positional notation with a radix of 2. Numbers represented in this system are commonly called binary numbers. Because of its straightforward implementation in digital electronic circuitry using logic gates, the binary system is used internally by almost all modern computers and computer-based devices such as mobile phones.…

    • 2502 Words
    • 11 Pages
    Powerful Essays