Top Banner
Working with Numbering Systems By Larry Long Learning Objectives To understand the principles of numbering systems To convert numbers from one base to another To be able to do arithmetic in binary and hexadecimal This supplement to Long and Long learning resources (published by Prentice Hall) on computer competency presents the principles of numbering systems, discusses numbering-system arithmetic, and illustrates how to convert a value in one numbering system to its equivalent in another. After studying this supplement you will be able to perform rudimentary arithmetic operations in the binary and hexadecimal numbering systems. CONTENTS Numbering Systems and Computers Principles of Numbering Systems Converting Numbers from One Base into Another Arithmetic in Binary and Hexadecimal Examples of Binary Arithmetic Examples of Hexadecimal Arithmetic Self - Check with Answers NUMBERING SYSTEMS AND COMPUTERS We humans use a decimal, or base-10, numbering system, presumably because people have 10 fingers. If we had three fingers and a thumb on each hand, as does the Extra Terrestrial (E.T.), from the classic movie, and Homer Simpson of the Simpson’s, then in all probability we would be using the octal numbering system, which has a base of 8. Early computers were designed around the decimal numbering system. This approach made the creation of computer logic capabilities unnecessarily complex and did not make efficient use
15

Working with Numbering Systems CONTENTS Numbering Systems and Computers Principles of Numbering Systems Converting Numbers from One Base into Another Arithmetic in Binary and Hexadecimal

Feb 06, 2023

Download

Documents

Semesta Alam
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Working with Numbering Systems CONTENTS Numbering Systems and Computers Principles of Numbering Systems Converting Numbers from One Base into Another Arithmetic in Binary and Hexadecimal

Working with Numbering Systems

By Larry Long

Learning Objectives To understand the principles of numbering systems To convert numbers from one base to another To be able to do arithmetic in binary and hexadecimal

This supplement to Long and Long learning resources (published byPrentice Hall) on computer competency presents the principles ofnumbering systems, discusses numbering-system arithmetic, andillustrates how to convert a value in one numbering system to itsequivalent in another. After studying this supplement you will beable to perform rudimentary arithmetic operations in the binaryand hexadecimal numbering systems.

CONTENTSNumbering Systems and Computers Principles of Numbering Systems Converting Numbers from One Base into Another Arithmetic in Binary and Hexadecimal Examples of Binary Arithmetic Examples of Hexadecimal Arithmetic Self - Check with Answers

NUMBERING SYSTEMS AND COMPUTERSWe humans use a decimal, or base-10, numbering system, presumablybecause people have 10 fingers. If we had three fingers and athumb on each hand, as does the Extra Terrestrial (E.T.), from theclassic movie, and Homer Simpson of the Simpson’s, then in allprobability we would be using the octal numbering system, whichhas a base of 8.

Early computers were designed around the decimal numberingsystem. This approach made the creation of computer logiccapabilities unnecessarily complex and did not make efficient use

Page 2: Working with Numbering Systems CONTENTS Numbering Systems and Computers Principles of Numbering Systems Converting Numbers from One Base into Another Arithmetic in Binary and Hexadecimal

of resources. (For example, 10 vacuum tubes were needed torepresent one decimal digit.) In 1945, as computer pioneers werestruggling to improve this cumbersome approach, John von Neumannsuggested that the numbering system used by computers should takeadvantage of the physical characteristics of electronic circuitry.To deal with the basic electronic states of on and off, vonNeumann suggested using the binary numbering system. His insighthas vastly simplified the way computers handle data.

Computers operate in binary and communicate to us in decimal.A special program translates decimal into binary on input, andbinary into decimal on output. Under normal circumstances, aprogrammer would see only decimal input and output. On occasion,though, he or she must deal with long and confusing strings of 1sand 0s that represent the content of RAM, the computers memory.Occasionally a programmer or computer engineer takes a snapshot ofthe contents of RAM (on-bits and off-bits) at a given moment intime. To reduce at least part of the confusion of seeing only 1sand 0s on the output, the hexadecimal (base-16) numbering systemis used as a shorthand to display the binary contents of both RAMand secondary storage, such as disk.

The decimal equivalents for binary, decimal, and hexadecimalnumbers are shown in Figure 1. We know that in decimal, any numbergreater than 9 is represented by a sequence of digits. When youcount in decimal, you "carry" to the next position in groups of10. As you examine Figure 1, notice that you carry in groups of 2in binary and in groups of 16 in hexadecimal. Also note that anycombination of four binary digits can be represented by one "hex"digit.

Page 3: Working with Numbering Systems CONTENTS Numbering Systems and Computers Principles of Numbering Systems Converting Numbers from One Base into Another Arithmetic in Binary and Hexadecimal

FIGURE 1 Numbering System Equivalence Table

The hexadecimal numbering system is used only for theconvenience of the programmer or computer scientist, or computerengineer when reading and reviewing the binary display of memory.Computers do not operate or process in hex. During the 1960s andearly 1970s, programmers often had to examine the contents of RAMto debug their programs (that is, to eliminate program errors).Today's programming languages have user friendly diagnostics(error messages) and computer-assisted tools that help programmersduring program development. These diagnostics and development aidshave minimized the need for applications programmers to convertbinary and hexadecimal numbers into their more familiar decimalequivalents. However, if you become familiar with these numberingsystems, you should achieve a better overall understanding ofcomputers. And, someday you may need to read hex to decode anerror message or set the jumpers on an expansion card.

PRINCIPLES OF NUMBERING SYSTEMS

BinaryThe binary, or base-2, numbering system is based on the sameprinciples as the decimal, or base-10, numbering system, withwhich we are already familiar. The only difference between the twonumbering systems is that binary uses only two digits, 0 and 1,and the decimal numbering system uses 10 digits, 0 through 9. Theequivalents for binary, decimal, and hexadecimal numbers are shownin Figure 1.

The value of a given digit is determined by its relativeposition in a sequence of digits. Consider the example in Figure2. If we want to write the number 124 in decimal, theinterpretation is almost automatic because of our familiarity withthe decimal numbering system. To illustrate the underlyingconcepts, let's give Ralph, a little green two-fingered Martian, abag of 124 (decimal) marbles and ask him to express the number ofmarbles in decimal. Ralph, who is more familiar with binary, wouldgo through the following thought process (see Figure 2).

Page 4: Working with Numbering Systems CONTENTS Numbering Systems and Computers Principles of Numbering Systems Converting Numbers from One Base into Another Arithmetic in Binary and Hexadecimal

FIGURE 2 Numbering System FundamentalsRalph, our two-fingered Martian who is used to counting in binary, might go through the thought process illustrated here when counting 124 marbles in decimal. Ralph's steps are discussed in the text.

Step 1. Ralph knows that the relative position of a digit within astring of digits determines its value, whether the numberingsystem is binary or decimal. Therefore, the first thing to dois determine the value represented by each digit position.

Step 2. Ralph knows that as in any numbering system, the rightmostposition has a value of the base to the zero power, or 1 (100

= 1). The second position is the base to the first power, or10 (101 = 10). The third position is the base squared, or100, and so on.

Step 3. Because the largest of the decimal system's 10 digits is9, the greatest number that can be represented in therightmost position is 9 (9 X 1). The greatest number that canbe represented in the second position, then, is 90 (9 X 10).In the third position, the greatest number is 900, and so on.Having placed the marbles in stacks of 10, Ralph knowsimmediately that there will be no need for a fourth-positiondigit (the thousands position). It is apparent, however, thata digit must be placed in the third position. Because placinga 2 in the third position would be too much (200 > 124),Ralph places a 1 in the third position to represent 100marbles.

Page 5: Working with Numbering Systems CONTENTS Numbering Systems and Computers Principles of Numbering Systems Converting Numbers from One Base into Another Arithmetic in Binary and Hexadecimal

Step 4. Ralph must continue to the second position to represent theremaining 24 marbles. In each successive position, Ralphwants to represent as many marbles as possible. In this case,a 2 placed in the second position would represent 20 of theremaining marbles (2 X 101 = 20).

Step 5. There are still four marbles left to be represented. Thiscan be done by inserting a 4 in the rightmost, or "ones,"position.

Step 6. The combination of the three numbers in their relativepositions represents 124 (decimal).

Ralph would go through the same thought process if asked torepresent the 124 (decimal) marbles using the binary numberingsystem (see Figure 3). To make the binary conversion processeasier to follow, the computations in Figure 3 are done in themore familiar decimal numbering system. See if you can traceRalph's steps as you work through Figure 3.

Page 6: Working with Numbering Systems CONTENTS Numbering Systems and Computers Principles of Numbering Systems Converting Numbers from One Base into Another Arithmetic in Binary and Hexadecimal

FIGURE 3 Representing a Binary NumberTo represent 124 marbles in binary, we would follow the same thought processas we would in decimal (see Figure 2), but this time we have only two digits(0 and 1). For ease of understanding, the arithmetic is done in decimal.

HexadecimalPerhaps the biggest drawback to using the binary numbering systemfor computer operations is that programmers may have to deal withlong and confusing strings of 1s and 0s. To reduce the confusion,the hexadecimal, or base-16, numbering system is used as shorthandto display the binary contents of primary and secondary storage.

Notice that the bases of the binary and hexadecimal numberingsystems are multiples of 2: 2 and 24, respectively. Because ofthis, there is a convenient relationship between these numberingsystems. The numbering-system equivalence table shown in Figure 1illustrates that a single hexadecimal digit represents four binarydigits (01112 = 716, 11012 = D16, 10102 = A16 where subscripts areused to indicate the base of the numbering system). Notice that inhexadecimal, or "hex," letters are used to represent the six higherorder digits.

Two hexadecimal digits can be used to represent the eight-bit

Page 7: Working with Numbering Systems CONTENTS Numbering Systems and Computers Principles of Numbering Systems Converting Numbers from One Base into Another Arithmetic in Binary and Hexadecimal

byte of an EBCDIC equals sign (=) (011111102 is the same as 7E16).Figure 4 illustrates how a string of EBCDIC bits can be reduced toa more recognizable form using hexadecimal.

FIGURE 4 System Expressed in Different WaysThe word System is shown as it would appear in input/output, internal binarynotation, and hexadecimal notation.

We will now examine how to convert one number in a numberingsystem to an equivalent number in another numbering system. Forexample, there are occasions when we might wish to convert ahexadecimal number into its binary equivalent. We shall also learnthe fundamentals of numbering-system arithmetic.

CONVERTING NUMBERS FROM ONE BASE INTO ANOTHER

Decimal to Binary or HexadecimalA decimal number can be converted easily into an equivalent numberof any base by the use of the division/remainder technique. Thistwo-step technique is illustrated in Figure 5. Follow these stepsto convert decimal to binary.

Page 8: Working with Numbering Systems CONTENTS Numbering Systems and Computers Principles of Numbering Systems Converting Numbers from One Base into Another Arithmetic in Binary and Hexadecimal

FIGURE 5 Converting a Decimal Number into Its Binary EquivalentUse the twoBstep division/remainder technique to convert a decimal number intoan equivalent number of any base.

Step 1. Divide the number (19, in this example) repeatedly by 2,and record the remainder of each division. In the firstdivision, 2 goes into 19 nine times with a remainder of 1.The remainder is always one of the binary digits--0 or 1. Inthe last division you divide 1 by the base (2) and theremainder is 1.

Step 2. Rotate the remainders as shown in Figure 5; the result(10011) is the binary equivalent of a decimal 19.

Figure 6 illustrates how the same division/remainder technique isused to convert a decimal 453 into its hexadecimal equivalent(1C5). In a decimal-to-hex conversion, the remainder is always one ofthe 16 hex digits.

FIGURE 6 Converting a Decimal Number into Its Hexadecimal EquivalentThe two-step division/remainder technique is used to convert a decimal numberto its hex equivalent.

Binary to Decimal and Hexadecimal To convert from binary to decimal, multiply the 1s in a binary numberby their position values, then sum the products (see Figure 7). InFigure 7, for example, binary 11010 is converted into its decimal

Page 9: Working with Numbering Systems CONTENTS Numbering Systems and Computers Principles of Numbering Systems Converting Numbers from One Base into Another Arithmetic in Binary and Hexadecimal

equivalent (26).

FIGURE 7 Converting a Binary Number into Its Decimal EquivalentMultiply the 1s in a binary number by their position values.

The easiest conversion is binary to hex. To convert binary tohex, simply begin with the 1s position on the right and segmentthe binary number into groups of four digits each (see Figure 8).Refer to the equivalence table in Figure 2, and assign each groupof four binary digits a hex equivalent. Combine your result, andthe conversion is complete.

Hexadecimal to BinaryTo convert hex numbers into binary, perform the grouping procedurefor converting binary to hex in reverse (see Figure 8).

FIGURE 8 Converting a Binary Number into Its Hexadecimal EquivalentPlace the binary digits in groups of four, then convert the binary numberdirectly to hexadecimal.

Hexadecimal to Decimal Use the same procedure as that used for binary-to-decimal

Page 10: Working with Numbering Systems CONTENTS Numbering Systems and Computers Principles of Numbering Systems Converting Numbers from One Base into Another Arithmetic in Binary and Hexadecimal

conversions (see Figure 7) to convert hex to decimal. Figure 9demonstrates the conversion of a hex 3E7 into its decimalequivalent of 999.

FIGURE 9 Converting a Hexadecimal Number into Its Decimal EquivalentMultiply the digits in a hexadecimal number by their position values.

ARITHMETIC IN BINARY AND HEXADECIMALThe essentials of decimal arithmetic operations have been drilledinto us so that we do addition and subtraction almost by instinct.We do binary arithmetic, as well as that of other numberingsystems, in the same way that we do decimal arithmetic. The onlydifference is that we have fewer (binary) or more (hexadecimal)digits to use. Figure 10 illustrates and compares addition andsubtraction in decimal with that in binary and hex. Notice inFigure 10 that you carry to and borrow from adjacent positions,just as you do in decimal arithmetic.

FIGURE 10 Binary, Decimal, and Hexadecimal Arithmetic ComparisonAs you can see, the only difference in doing arithmetic in the variousnumbering systems is the number of digits used.

Page 11: Working with Numbering Systems CONTENTS Numbering Systems and Computers Principles of Numbering Systems Converting Numbers from One Base into Another Arithmetic in Binary and Hexadecimal

Examples of Binary Arithmetic Example 1 Addition

Example 2 Addition

Example 3 Subtraction

Page 12: Working with Numbering Systems CONTENTS Numbering Systems and Computers Principles of Numbering Systems Converting Numbers from One Base into Another Arithmetic in Binary and Hexadecimal

Example 4 Subtraction

Examples of Hexadecimal Arithmetic Example 1 Addition

Page 13: Working with Numbering Systems CONTENTS Numbering Systems and Computers Principles of Numbering Systems Converting Numbers from One Base into Another Arithmetic in Binary and Hexadecimal

Example 2 Addition

Example 3 Subtraction

Page 14: Working with Numbering Systems CONTENTS Numbering Systems and Computers Principles of Numbering Systems Converting Numbers from One Base into Another Arithmetic in Binary and Hexadecimal

Example 4 Subtraction

Self-Check

1. The hex numbering system has a base of ________, and thebinary numbering system has a base of ________.

2. The value of a particular digit in a number is determined byits relative position in a sequence of digits. (T/F)

3. A single hexadecimal digit can represent how many binarydigits: (a) two, (b) three, or (c) four?

4. The bases of the binary and decimal numbering systems are

Page 15: Working with Numbering Systems CONTENTS Numbering Systems and Computers Principles of Numbering Systems Converting Numbers from One Base into Another Arithmetic in Binary and Hexadecimal

multiples of 2. (T/F)5. The binary equivalent of a decimal 255 is ________.6. The binary equivalent of a hexadecimal 1C is ________.7. The decimal equivalent of a hexadecimal 1B6 is ________.8. The hexadecimal equivalent of a decimal 129 is ________.9. The decimal equivalent of a binary 110101 is ________.10. The hexadecimal equivalent of a binary 1001 is ________.11. The binary equivalent of a decimal 28 is ________.12. The binary equivalent of a hexadecimal 35 is ________.13. The decimal equivalent of a hexadecimal 7 is ________.14. The hexadecimal equivalent of a decimal 49 is ________.15. The decimal equivalent of a binary 110110110 is

________.16. The hexadecimal equivalent of a binary 1110 is ________.17. The result of 1012 + 112 is ________ (in binary).18. The result of A116 + BC16 + 1016 is ________ (in

hexadecimal).19. The result of 6010 + F116 - 10010012 is ________ (in

decimal).20. The result of 112 + 278 + 9310 - B16 is ________ (in

decimal). Self-test answers. 1. 16, 2. 2. T. 3. 4. 4. F. 5. 11111111. 6. 11100.7. 438. 8. 81. 9. 53. 10. 9. 11. 11100. 12. 110101. 13. 7. 14.31. 15. 438. 16. E. 17. 10002. 18. 16D16. 19. 22810. 20. 10810.

Go to top

Note to instructors: Feel free to use or distribute this document toyour students for as long as you use a Prentice Hall book by Larryor Nancy Long.

©2000 Prentice-Hall, Inc.A division of Pearson EducationUpper Saddle River, New Jersey 07458Legal Statement