You are on page 1of 8

Digital Electronic Systems Unit 2

Binary Numbers and Arithmetic


In order to perform functions such as comparison and arithmetic, it is necessary to represent
numbers in binary. This unit introduces binary numbers, outlines their relationship with the
decimal number system and proceeds to introduce binary arithmetic. The decimal number
system is reviewed first to help understand the structure of other number systems.
Decimal Number System
It is not surprising that human anatomy helps describe the most common number system used
today. A human hand is characterised by four fingers and a thumb, thus this gives a range of
ten numbers from 0 to 9. This does not mean however that we are limited to a scale of ten
numbers, as the position of these numbers can be used to indicate their magnitude and thus
can be assigned a weight.
10n

102

..

101

100

10-1

10-2

..

10-n

Decimal point

For example:
3410 = 30 + 4
3

4
4 * 100 = 4
3 * 101= 30
Sum=3410

As can be seen, the number 3 has a weighting of 10 (101) due to its position and the number 4
has a weighting of 1 (100) due to its position
For example:
123.4510 = 100 + 20 + 3 + (4/10) + (5/100)
= (1 * 102) + (2 * 101) + (3 * 100) + (4 * 10-1) + (5 * 10-2)
Note, a number with a subscript of 10 (i.e. Base 10) indicates that this is a decimal number.
However, decimal is the default number system, so usually the subscript is not included for
decimal numbers.

Digital Electronic Systems Unit 2

Binary Number System


The binary system has two symbols. This is just another way of counting, and it is less
complicated than decimal as it is composed of only two binary digits (bits), 0 and 1.
Counting in binary is very similar to counting in decimal. As previously stated, the decimal
system only contains ten digits in total but this does not limit us to counting only from 0 to 9.
When the number 9 is reached, another column (to the left) is started and the counting
continues from 10 to 99, where the process is repeated.
The system of binary counting is similar. Binary being a two-digit number system it starts at
0 and then goes to 1. To continue counting, as with the decimal systems, another digit must
be added to the left, i.e. continue counting from 10 to 11. The next column is 100 101 110
111.
The subscript 2 is used to indicate that a number is binary, for example, 10 2 is a binary
number.
COUNT
zero
one
two
three
four
five
six
seven
eight
nine
ten
eleven
twelve
thirteen
fourteen
fifteen

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

BINARY
02
12
102
112
1002
1012
1102
1112
10002
10012
10102
10112
11002
11012
11102
11112

As can be seen from the table above, it takes four bits to count sixteen decimal numbers. A
simple formula is used to calculate how far it is possible to count with n bits, i.e. 2n-1, where
n is the number of bits available.
For Example:

n =4
24-1 = 16 - 1
= 15

Therefore, it is possible to count to the decimal number fifteen with four binary digits. To
count to sixteen a fifth binary digit (bit) is needed.
Computers use binary numbers to select memory locations. Each location is assigned a
unique number (called an address). The Pentium Microprocessor has 32 address lines, which
means it has
232 = 4,294,967,296
unique locations.
2

Digital Electronic Systems Unit 2

Binary to Decimal conversion


Like the decimal number system, the binary number system is also a weighted system, i.e. the
position of a 1 or a 0 indicates its weighting. Using the weighted system, any binary number
can be divided into parts that are to the power of two. Then, using their weighting the binary
number can be converted to decimal.
Ex 1: Convert the binary number 10012 to a decimal number.

[910]

Ex 2: Convert the binary number 1110112 to a decimal number.

[5910]

Binary Representation of Fractional Numbers


The above examples are whole numbers, but fractional numbers can also be represented in
binary by placing bits to the right of the binary point.
2n

..

22

21

20

2-1

2-2

..

2-n

Binary point

All bits to the left of the binary point have weights that are positive powers of 2 and all to the
right have weights that are negative powers of two, i.e. fractional weights:
2-1
2-2
2-3
2-4

= 1/21
= 1/2
2
= 1/2
= 1/4
= 1/23
= 1/8
= 1/24
= 1/16
:
The same process is used when converting decimal fractions.
Ex 3: Convert the binary number 0.11012 to a decimal number.

[0.812510]

Ex 4: Convert the binary number 11001.0112 to a decimal number.

[25.37510]

Alternative method of converting Binary fractions into decimal numbers


If we ignore the decimal point and convert the binary number into a decimal number, then we
know how many binary digits there are. Thus we know how many possible combinations
there are. Dividing these two numbers we obtain the decimal fraction. Repeating Ex 3 will
illustrate the point:
Convert the binary number 0.11012 into a decimal number.
Ignoring the decimal point we have the binary number 1101 2. This translates (via above
methods) into the decimal number 1310. There are four binary digits in this number, this
implies that there are 24=16 possible combinations.

Digital Electronic Systems Unit 2

Dividing 1310 by the total number of combinations, we obtain 13/16=0.8125 which is the
same as in the last calculation.
0.11012 = 0.812510

Decimal to Binary conversion


We can also convert a decimal number into a binary number by a successive division process.
The decimal number is divided continuously by 2 and the remainders indicate the equivalent
binary number. The binary number is read from the last remainder upwards to the first.

Ex 5: Convert the decimal number 123 to a binary number.

[11110112]

Ex 6: Convert the decimal number 79 to a binary number.

[10011112]

Ex 7: Convert the decimal number 46 to a binary number.

[1011102]

The procedure is a little more complicated when we have a decimal number that has digits
attached to the right of the decimal point. The successive division method is used for those
digits to the left of the decimal point, as before. However the digits to the right of the
decimal point undergo a different transformation. Instead of being divided continuously by
two, they are multiplied continuously by two. This happens until there are no numbers to the
right of the decimal point. The binary number is read from the first carry to the last carry.
Ex 8: Convert the decimal number 0.75 to binary.

[0.1102]

If in doubt, you can verify your answer easily by doing a binary to decimal conversion.
ForEx 8,

0.112 1 1 1 1
2
4
0.7510
Ex 9: Convert the decimal number 0.875 to binary.
Ex 10: Convert the decimal number 27.125 to binary.
Ex 11: Convert the decimal number 32.48 to binary (to 5 places).

[0.11102]
[11011.0012]
[100000.011112]

Digital Electronic Systems Unit 2

Binary Arithmetic
Binary Addition
There are four basic rules for adding binary digits
02 + 02 = 02
(Sum of 0 with a carry of 0)
12 + 02 = 12
(Sum of 1 with a carry of 0)
02 + 12 = 12
(Sum of 1 with a carry of 0)
12 + 12 = 102
(Sum of 0 with a carry of 1)
Some examples:
12 + 02 + 02 = 012
12 + 12 + 02 = 102
12 + 02 + 12 = 102
12 + 12 + 12 = 112

(Sum of 1 with a carry of 0)


(Sum of 0 with a carry of 1)
(Sum of 0 with a carry of 1)
(Sum of 1 with a carry of 1)

Some more complex examples (given with there decimal equivalent)


Ex 12: 1012 (5)+ 0112 (3)

[10002 (8)]

Ex 13: 1112 (7)+ 1102 (6)

[11012 (13)]

Ex 14: 11112 (15)+ 1102 (6)

[101012 (21)]

Ex 15: 10112 (11)+ 11102 (14) +10012 (9)+ 11012 (13)


Ex 16: 0.010102 (0.3125)+ 0.110112 (0.84375)

[1011112 (47)]
[1.001012 (1.15625)]

Negative numbers
Consideration is now given to how negative numbers are represented. A signed binary
number consists of both sign and magnitude information. The sign indicates whether the
number is positive or negative and the magnitude is the value of the number. There are three
ways in which signed whole numbers can be expressed in binary form:
Sign-Magnitude
The left-most bit is the sign bit, and the remaining bits are magnitude bits. In the sign
magnitude system, the negative number has the same magnitude as the corresponding
positive number but the sign bit is a 1 rather than a 0.

Digital Electronic Systems Unit 2

Example:
Sign Bit

Magnitude Bits

00011001 +25
10011001
Sign Bit

-25

Magnitude Bits

In this case, there are 7 magnitude bits, so the largest magnitude is 2 7-1=127. Therefore, this
number system ranges from 127 to +127.
1s Complement System
Positive numbers here are the same as in the sign-magnitude system. However, a negative
number is the 1s complement of the corresponding positive number. The 1s complement of
binary numbers is found by changing all 1s to 0s and all 0s to 1s. Again the most significant
bit (MSB) indicates whether the number is positive or negative.
Example:
00011001
11100110

+25
-25

2s Complement System
Positive numbers here are again the same as for the 1s Complement and Sign-Magnitude
systems. However, a negative number is the 2s complement of the corresponding positive
number. The 2s complement of a binary number is found by adding 1 to the least significant
bit (LSB) of the 1s complement. Again the most significant bit (MSB) indicates whether the
number is positive or negative.
Example:
00011001
11100111

+25
-25

For 2s complement signed numbers, the range of values for n-bit numbers is
-(2n-1) to (2n-1-1)
where in each case there is one sign bit and (n-1) magnitude bits.
So for this example, n=8, and numbers can be represented in 2s Complement from 128 to
+127.

Digital Electronic Systems Unit 2

In summary:
1011 0110 10002
0100 1001 01112
+12
0100 1001 10002

Binary Number
1s Complement
Add 1
2s Complement

An alternative method useful for finding the 2s Complement of long binary numbers is to
start at the right, with the LSB, and write the bits as they are up to and including the first 1.
Then take the 1s complement of the remaining bits.
101101101000
These bits remain as
they are
010010011000
1s complement of the
original bits
Ex 17 : For each binary number in a 4 bit system, (n=4) find the decimal representation in
sign magnitude, ones complement and twos complement.
4 BIT
BINARY
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111

SIGNMAGNITUDE

1S
COMPLEMENT

2S
COMPLEMENT

When dealing with negative binary numbers, it is important to know where the sign bit is.
Describing the number system used as an n-bit binary number system specifies this. This
indicates that the nth bit is the sign bit.
When two numbers in twos complement format are added, the result will be in twos
complement format. Hence, computers use the 2s complement to represent negative integer
numbers in all arithmetic operations.
7

Digital Electronic Systems Unit 2

Ex 18: Add the 8-bit 2s comp. binary numbers 00000111 and 00000100. Verify your answer
by converting the numbers being added and the result to decimal. [000010112 (11)]
Ex 19: Add the 8-bit 2s comp. binary numbers 00001111 and 11111010. Verify your answer
by converting the numbers being added and the result to decimal. [000010012 (9)]
Ex 20: Add the 8-bit 2s comp. binary numbers 00010000 and 11101000. Verify your answer
by converting the numbers being added and the result to decimal. [111110002 (-8)]
Ex 21: Add the 8-bit 2s comp. binary numbers 11111011 and 11110111. Verify your answer
by converting the numbers being added and the result to decimal. [111100102 (-14)]
Binary Subtraction
Subtraction is a special case of addition. For example, subtracting +6 from +9 is the same as
adding 6 to +9. Subtraction of two numbers is the same as taking the 2s complement of the
number you are subtracting and adding the two numbers, while discarding any final carry
bit.
Ex 22: Evaluate 000011102-000010012. Verify your answer by converting the numbers being
subtracted and the result to decimal.
[000001012 (5)]
Ex 23: Evaluate 000010012-000011102. Verify your answer by converting the numbers being
subtracted and the result to decimal.
[-000001012 (-5)]
When two numbers are added and the number of bits required to represent the sum exceeds
the number of bits in the two numbers, an overflow condition results and is indicated by an
incorrect sign bit.
Ex 24: Add the 8-bit binary numbers 01111101 and 00111010. Determine whether or not
your answer is correct by converting the numbers being added and the result to decimal.
What is the answer if a 12-bit binary system is used?
[101101112 (183)]
Binary Multiplication
Binary Multiplication is analogous to decimal multiplication. Negative binary numbers must
be changed to uncomplemented form before binary multiplication.
Ex 25: Multiply 101012 by 1102. Verify your answer by converting the numbers being
multiplied and the result to decimal.
[11111102 (126)]
Binary Division
Binary Division is analogous to decimal division. Negative binary numbers must be changed
to uncomplemented form before binary division.
Ex 26: Divide 110112 by 1102. Verify your answer by converting the numbers being divided
and the result to decimal.
[100.102 (4.5)]

You might also like