Вы находитесь на странице: 1из 13

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

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, 1, 2, 3, 4, 5, 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, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F (Note: In base 10, A = 10, B = 11, C = 12, D = 13, E = 14, 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, 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

v) Mixed Conversions (e.g. base 3 to base 5)

When performing these conversion, it becomes important for students to indicate the base that the number is written in, as it will become very easy to confuse how the number is being represented. This can be done by writing the base as a subscript at the end of the number ( e.g. 4327 in base 8 can be written as 43278 ). 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. The following are some examples to demonstrate this technique. 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

To convert from decimal to any other base, 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). When dividing by the powers of the new base, it is important not to leave out any of the powers, even if the number does not divide into it. 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. 1 OR 1

0 0 1

1 1 0 1 1 0 1

0 0 1

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

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, we start with this number. 1 2

5 7

We obtain the octal equivalent by reading down the column. 68710 = 12578

iii) Binary to Octal/Hexadecimal Binary numbers require three digits to be able to represent one digit in octal. When converting binary to octal, we can group the binary number into groups of three digits starting from the right, and convert each group of three digits to one octal digit. e.g. 101110112 = = = 010 2 2738 111 7 011 3

Similarly, binary numbers require four digits to be able to represent one digit in hexadecimal. When converting from binary to hexadecimal, we can group the binary number into groups of four digits starting from the right, and convert each group of four digits to one hexadecimal digit. e.g. 10110000112 = 0010 = 2 = 2C416 1100 C 0011 4

iv) Octal/Hexadecimal to Binary Since one octal digit can be represented using three binary digits, we can convert each octal digit into a group of three binary digits. e.g. 2638 = 010 110 011 = 101100112

Since one hexadecimal digit can be represented using four binary digits, we can convert each hexadecimal digit into a group of four binary digits. e.g. 2A4E16 = 0010 1010 0100 1110 = 101010010011102

v) Mixed Conversions If we need to convert between bases that are not described above - for example, between base 5 and base 7 - then you can use the following procedure. First convert the number to decimal, since we know how to convert any base to decimal - in our example we would convert from base 5 to decimal. Then, convert the decimal equivalent to the new base, since we know how to convert decimal to any base - in our example we would convert from decimal to base 7. Using this two step method, we are able to convert between any bases.

Adding Binary Numbers When adding binary numbers, there are four cases that you need to consider:

Most of these seem fairly obvious, except for possibly the case when we add to ones together. Logically, when we add two ones together we get two. Since we are adding in binary, we need to use the binary representation of 2, which is 10. This example shows us that for each group of two ones, we need to carry a one to the next column. This idea will become clear in the next few examples.

e.g. 1

e.g. 2

In the second example, it is clear to see that for each pair of ones, we carry a one to the next column.

Multiplying Binary Numbers Similar to addition of binary numbers, there are four cases that we need to look at when multiplying binary numbers.

e.g. 1 Multiply 101 by 11

e.g. 2 Multiply 100111 by 110101

Negative Binary Numbers So far, when we have been looking at binary numbers, we have treated the 1's and 0's as numbers or digits. However, when we include negative numbers in this system, we have to take a slightly different view of binary numbers. We will now treat these 1's and 0's as codes for numbers, where the left most digit will be the sign digit, indicating whether the number is positive or negative. If the left most digit is 0 the number is positive, and if the left most digit is 1 the number is negative. We will now use this positive/negative convention and apply it to two different ways of representing negative numbers - ones compliment and twos compliment.

Ones Compliment The ones compliment is found by changing the zeros for ones and ones for zeros when forming the negative number. 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). 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. e.g. +3 = 0011 ones : compliment : add 1 1100 1101 = 3 in twos compliment

To go back to +3:

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). 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. Once you know how to find negative numbers, subtraction follows quite nicely (although it is a little complicated). For subtraction we can use the following rule: A B = A + ( B) Looking at the right side of this equation, we know how to add two numbers and we know how to find the compliment, so it is possible for us to evaluate the right side. However, there are a few problems that arise when trying to use ones and twos compliment (twos compliment is more effective, but you will run into problems when the number required is larger than the number of bits you are using. e.g. 5+7=12 ; 5 and 7 can be represented using only four digits, but 12 cannot. You will run into overflow problems if you use 4 digits, but will be fine if you use 5 digits).

Binary Coded Decimals

Another way to represent decimals in binary form is binary coded decimals (BCD's). BCD's are binary numbers that code each decimal digit separately as a four digit binary number. e.g. 95 = 1001. 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. However, BCD's have several disadvantages. They use more memory since each decimal digit requires four binary digits and arithmetic operations are difficult to program and significantly slower.

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. This allows all numbers to be represented using the same basic form, with unlimited size. However, there is a slight disadvantage that all numbers cannot be represented with total accuracy. The following example shows how a number can be stored using this representation. e.g. 104 = 1.04 102 01101000 = .1101 20111 (base 10) (base 2)

mantissa Computer Representation: Exponent Mantissa

Exponent

0000 0111

0110100 00000000 00000000

sign digit

sign digit

Note: the exponent and mantissa are represented using twos compliment

Вам также может понравиться