You are on page 1of 7

Mathematical operations on binary numbers

Digital Logic Design -0403201

Dr. Ali El-Moursy

1.

Match number of bits between the two numbers

Unsigned representation: extend number with less bits to the left with zeros to match the larger number of bits (n bits)

Signed 2s complement representation:

If MSB in less bits number = 1 then extend number with less bits to the left with ones to match the larger number of bits (n bits)

If MSB in less bits number = 0 then extend number with less bits to the left with zeros to match the larger number of bits (n bits)

Digital Logic Design -0403201

Dr. Ali El-Moursy

2.

Check the operation Addition or subtraction

Addition: - go to step 3

Subtraction: - Convert subtrahend to 2s complement - go to step 3

3.

Perform the addition between the two numbers. Consider to show the carry for each bit addition.

Digital Logic Design -0403201

Dr. Ali El-Moursy

4.

Check for the overflow condition to know how many bits are containing your result

Unsigned representation:

Signed 2s complement representation: - If Carry-in to the sign bit & Carry-out are not similar then overflow occurs

Addition: -If Carry-out =1 then overflow occurs

Subtraction: - NO overflow could happen whether carry-out =1 or not

Digital Logic Design -0403201

Dr. Ali El-Moursy

5.

Get the Full result according to the overflow detection

Overflow: -Full result is in n+1 bits one carry-out bit + n bits of result

No overflow: -Full result is in n bits (result of the addition) so the carry-out SHOULD be discarded whether it is 1 or 0

Digital Logic Design -0403201

Dr. Ali El-Moursy

6.

Check for the sign of the result considering ALL bits of your result as derived in step 4

Unsigned representation:

Signed 2s complement representation:

Addition: -No ve number could happen When adding two unsigned (+ve) numbers

Subtraction:

MSB = 0 then Result +ve

MSB = 1 then Result -ve

Carry-out =1 then result +ve

Carry-out =0 then result -ve

Digital Logic Design -0403201

Dr. Ali El-Moursy

7.

Convert binary result to decimal

Result is +ve then Use the rule (equation)

Result is -ve then a) Convert result to 2s-complement b) Use the rule (equation) c) Put ve sign in front of the value

Digital Logic Design -0403201

Dr. Ali El-Moursy

You might also like