# Number Systems

Introduction

Although many students know the decimal (base 10) system, and are very comfortable with performing operations using this system, it is important for students to understand that the decimal system is not the only system. By studying other number systems such as binary (base 2), octal (base 8), and hexadecimal (base 16), students will gain a better understanding of how number systems work in general. When discussing how a computer stores information, the binary number system becomes very important since this is the system that computers use. It is important that students understand that computers store and transmit data using electrical pulses, and these pulses can take two forms - "on" (1) or "off" (0). The following topics treat the manipulation of numbers represented in different bases as well as the binary representation of negative integers and floating-point numbers.

Different Bases The following are a series of examples that should help students understand how numbers are represented using different bases. DECIMAL (base 10) possible digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 874 693 125 = 8× 100 000 000 + 7× 10 000 000 + 4× 1 000 000 + 6× 100 000 + 9× 10 000 + 3× 1 000 + 1× 100 + 2× 10 + 5× 1 = 8× 108 + 7× 107 + 4× 106 + 6× 105 + 9× 104 + 3× 103 + 1× 102 + 2× 101 + 5× 100

BINARY (base 2) possible digits: 0, 1

D = 13. 3. 1. C. B. 8.110 010 101 = 1× 256 + 1× 128 + 0× 64 + 0× 32 + 1× 16 + 0× 8 + 1× 4 + 0× 2 + 1× 1 = 1× 28 + 1× 27 + 0× 26 + 0× 25 + 1× 24 + 0× 23 + 1× 22 + 0× 21 + 1× 20 OCTAL (base 8) possible digits: 0. B = 11. 1. 7. C = 12. 2. 6. 7 7 426 351 = 7× 262 144 + 4× 32 768 + 2× 4096 + 6× 512 + 3× 64 + 5× 8 + 1× 1 = 7× 86 + 4× 85 + 2× 84 + 6× 83 + 3× 82 + 5× 81 + 1× 80 HEXADECIMAL (base 16) possible digits: 0. E. A. 4. D. 4. 6. 3. E = 14. 5. there is five different types of conversions that the students will need to remember: i) Any Base → Decimal ii) Decimal → Any Base iii) Octal/Hexadecimal → Binary iv) Binary → Octal/Hexadecimal . 2. F = 15) 3B 2C4 = 3× 65 536 + B× 4096 + 2× 256 + C× 16 + 4× 1 = 3× 164 + B× 163 + 2× 162 + C× 161 + 4× 160 Converting Between Bases When converting numbers from one base to another. A = 10. 5. F (Note: In base 10. 9.

g. This can be done by writing the base as a subscript at the end of the number ( e. base 3 to base 5) When performing these conversion.g. Binary to Decimal 1010012 = 1× 25 + 0× 24 + 1× 23 + 0× 22 + 0× 21 + 1× 20 = 32 + 8 + 1 = 4110 Octal to Decimal 47348 = 4× 83 + 7× 82 + 3× 81 + 4× 80 = 4× 512 + 7× 64 + 3× 8 + 4× 1 = 2 52410 Hexadecimal to Decimal 2BC4 = 2× 163 + B× 162 + C× 161 + 4× 160 = 2× 4096 + 11× 256 + 12× 16 + 4× 1 = 11 20410 ii) Decimal → Any Base . i) Any Base → Decimal Converting numbers to decimal from any other base is as easy as expanding the number to its power representation as above. as it will become very easy to confuse how the number is being represented. it becomes important for students to indicate the base that the number is written in. 4327 in base 8 can be written as 43278 ).v) Mixed Conversions (e. The following are some examples to demonstrate this technique.

it is important not to leave out any of the powers. even if the number does not divide into it. When dividing by the powers of the new base. →1 OR →1 →0 →0 →1 . Decimal to Binary 36410 → binary 29 = 512 28 = 256 27 = 128 26 = 64 25 = 32 24 = 16 23 = 8 22 = 4 21 = 2 20 = 1 Since 256 is the largest power that divides 364 evenly. we start dividing with 256. you can consecutively divide the decimal number by the powers of the base you are converting to. starting with the largest power that evenly divides the decimal number and continuing until you divide by 1 (power of zero).To convert from decimal to any other base.

→1 →1 →0 →1 →1 →0 →1 →0 →0 →1 →1 →0 →0 We obtain the binary equivalent by reading down the column. 36510 = 1011011002 .

→1 →2 →5 →7 We obtain the octal equivalent by reading down the column. e. we can group the binary number into groups of three digits starting from the right.Decimal to Octal 68710 → Octal 84 = 4096 83 = 512 82 = 64 81 = 8 80 = 1 Since 512 is the largest number that divides 687 evenly. 68710 = 12578 iii) Binary to Octal/Hexadecimal Binary numbers require three digits to be able to represent one digit in octal. and convert each group of three digits to one octal digit.g. 101110112 = = = 010 2 2738 111 7 011 3 . we start with this number. When converting binary to octal.

e. e.in our example we would convert from decimal to base 7. we can convert each hexadecimal digit into a group of four binary digits. we are able to convert between any bases. Then.g. convert the decimal equivalent to the new base.Similarly. e. since we know how to convert decimal to any base . 2638 = 010 110 011 = 101100112 Since one hexadecimal digit can be represented using four binary digits.g. binary numbers require four digits to be able to represent one digit in hexadecimal. and convert each group of four digits to one hexadecimal digit. 10110000112 = 0010 = 2 = 2C416 1100 C 0011 4 iv) Octal/Hexadecimal to Binary Since one octal digit can be represented using three binary digits. 2A4E16 = 0010 1010 0100 1110 = 101010010011102 v) Mixed Conversions If we need to convert between bases that are not described above . When converting from binary to hexadecimal. we can convert each octal digit into a group of three binary digits.g. . since we know how to convert any base to decimal . between base 5 and base 7 . we can group the binary number into groups of four digits starting from the right.in our example we would convert from base 5 to decimal.for example. First convert the number to decimal. Using this two step method.then you can use the following procedure.

g. when we add two ones together we get two. This idea will become clear in the next few examples. e.Adding Binary Numbers When adding binary numbers. Since we are adding in binary. Logically. we need to carry a one to the next column. 2 → → → → → In the second example. we need to use the binary representation of 2. . This example shows us that for each group of two ones. we carry a one to the next column. there are four cases that you need to consider: Most of these seem fairly obvious. 1 → → → → e. it is clear to see that for each pair of ones. which is 10.g. except for possibly the case when we add to ones together.

Multiplying Binary Numbers Similar to addition of binary numbers. . e. we have treated the 1's and 0's as numbers or digits. and if the left most digit is 1 the number is negative. when we include negative numbers in this system.g. However. there are four cases that we need to look at when multiplying binary numbers. where the left most digit will be the sign digit. We will now treat these 1's and 0's as codes for numbers. when we have been looking at binary numbers. 1 Multiply 101 by 11 e.ones compliment and twos compliment. We will now use this positive/negative convention and apply it to two different ways of representing negative numbers . indicating whether the number is positive or negative. we have to take a slightly different view of binary numbers. If the left most digit is 0 the number is positive. 2 Multiply 100111 by 110101 Negative Binary Numbers So far.g.

e.g. The following is a list of the numbers in ones compliment that can be formed using only four digits (remember that the left most digit is the sign digit). +3 = 0011 ones : compliment : add 1 1100 1101 = − 3 in twos compliment To go back to +3: .Ones Compliment The ones compliment is found by changing the zeros for ones and ones for zeros when forming the negative number. 0 1 2 3 4 5 6 7 0000 0001 0010 0011 0100 0101 0110 0111 0 -1 -2 -3 -4 -5 -6 -7 1111 1110 1101 1100 1011 1010 1001 1000 Notice that in ones compliment there is two ways to represent zero. Twos Compliment The twos compliment is obtained by forming the ones compliment first and then adding one.

Binary Coded Decimals . 5+7=12 . You will run into overflow problems if you use 4 digits. e.−3 ones compliment = 1101 : 0010 0011 = +3 in twos compliment add 1 : The following is a list of numbers in twos compliment that can be formed using only four digits (remember that the left digit is the sign digit). so it is possible for us to evaluate the right side. but you will run into problems when the number required is larger than the number of bits you are using. subtraction follows quite nicely (although it is a little complicated). but 12 cannot. 0 1 2 3 4 5 6 7 0000 0001 0010 0011 0100 0101 0110 0111 0 -1 -2 -3 -4 -5 -6 -7 0000 1111 1110 1101 1100 1011 1010 1001 Notice that in twos compliment there is only one representation for zero.g. we know how to add two numbers and we know how to find the compliment. 5 and 7 can be represented using only four digits. For subtraction we can use the following rule: A − B = A + (− B) → Looking at the right side of this equation. there are a few problems that arise when trying to use ones and twos compliment (twos compliment is more effective. Once you know how to find negative numbers. but will be fine if you use 5 digits). However.

BCD's are binary numbers that code each decimal digit separately as a four digit binary number. there is a slight disadvantage that all numbers cannot be represented with total accuracy. However. Floating Point Representation of Binary Numbers Another form that computers can use to represent numbers (remember that computers have to use some form of binary numbers) is to use scientific notation. 0101 = 10010101 (BCD) 217 = 0010 0001 0111 = 1000010111 (BCD) The advantage to using BCD's is the size of the number is unlimited with perfect accuracy. 95 = 1001.1101× 20111 (base 10) (base 2) mantissa Computer Representation: Exponent Mantissa Exponent . However. e.Another way to represent decimals in binary form is binary coded decimals (BCD's).g. with unlimited size. The following example shows how a number can be stored using this representation. 104 = 1. This allows all numbers to be represented using the same basic form. They use more memory since each decimal digit requires four binary digits and arithmetic operations are difficult to program and significantly slower.g.04× 102 01101000 = . e. BCD's have several disadvantages.

0000 0111 0110100 00000000 00000000 sign digit sign digit Note: the exponent and mantissa are represented using twos compliment .