You are on page 1of 13

Lect 4

Date: 8th August


Topics:
Signed binary arithmetic
Binary codes

8 August 2012
Binary Arithmetic
of
Signed Binary Numbers

8 August 2012 EEE/CS/ECE F215 2


Binary Arithmetic of Signed Binary Numbers

Two's Complement Addition/Subtraction


 Addition of n-bit signed numbers using Two's
Complement addition is straightforward.
 Addition is carried out in the same way as the
addition of n-bit positive numbers.
 Carry from the sign position (MSB) is ignored.
 If MSB = 1 after addition, the result is negative and
the magnitude is obtained by taking 2’s complement.
 Overflow occurs if the correct result (including the
sign) cannot be represented in n bits.
 Ex: 3+3, 3+(-2), 2+(-3), -3-3

8 August 2012 EEE/CS/ECE F215 3


Binary Arithmetic of Signed Binary Numbers

One's Complement Addition

 Similar to the addition of n-bit numbers using


Two's Complement Addition.
 Instead of discarding the carry from the sign
position (MSB), it must be added to the least
significant bit (LSB) of the n-bit sum.
 Ex: 3+3, 3+(-2), 2+(-3), -3-3

8 August 2012 EEE/CS/ECE F215 4


Diminished Radix complement and Radix complement
9’s and 10’s complement
1’s and 2’s complement

Given a number N in base r having n digits, the (r-1)’s complement


of N is defined as (rn – 1) – N.

Given a number N in base r having n digits, the r’s complement of N


is defined as rn – N.

Find 9’s complement and 10’s complement of 54.

Find 1’s complement and 2’s complement of 11.

8 August 2012 EEE/CS/ECE F215 5


Binary Codes

8 August 2012 6
Binary Codes

 Weighted and Unweighted Codes


− A weighted code is one in which each position in
the code has a specific weight
− An unweighted code is one in which the
positions in the code do not have a specific
weight

8 August 2012 EEE/CS/ECE F215 7


Binary weighted Codes

 Binary Coded Decimal (BCD)


− 4-bit binary number used to represent each decimal
digit
− Weighted code: 8-4-2-1
− The binary values 0000 .. 1001 are used to represent
the decimal digits 0 .. 9
− The binary values 1010 .. 1111 are not used.
− Represent 9, 12 in BCD code.

8 August 2012 EEE/CS/ECE F215 8


Binary weighted Codes
BCD Addition:

Do the following BCD additions-

4+5

0100 + 0101 = 1001

4+9

0100+1001 = ?

If the binary sum is > 1001, we add 0110 to obtain the correct BCD
sum.

0100+1001 = 1101>1001

So 1101+0110= 1 0011

13 in BCD form.
8 August 2012 EEE/CS/ECE F215 9
Binary weighted Codes
 2-4-2-1 Code
− Weighted code with w3 = 2, w2 = 4, w1 = 2, w0 = 1
 Excess-3 Code
− Obtained from the 8-4-2-1 (weighted code).
− Add 3 (00112) to each of the codes.

Ex: Represent 4 in Excess 3 and 2421 code.


0111, 0100

Represent 5 in Excess 3 and 2421 code.

What is the relation between 4 and 5 and their Excess 3 and 2421
code representations?
Excess 3 and 2421 codes are example of self complementing code.

8 August 2012 EEE/CS/ECE F215 10


Binary weighted Codes

8 August 2012 EEE/CS/ECE F215 11


Binary Unweighted Codes

 Gray Code(s)
− Unweighted code
− Code values for successive decimal digits differ in
exactly one bit.
− Example: 2-bit Gray Code
Decimal Binary Gray Code
0 00 00
1 01 01
2 10 11
3 11 10

8 August 2012 EEE/CS/ECE F215 12


Binary Unweighted Codes

4-bit Gray Code

EEE/CS/ECE F215 13
8 August 2012

You might also like