Calculations with Binary
Numbers
Binary Addition 2
Two 1-bit values
A B A+ B
0 0 0
0 1 1
1 0 1
1 1 10
“two”
Binary Addition 3
Two n-bit values
Add individual bits
Propagate carries
For example
1 1
10101 21
+ 11001 + 25
101110 46
Binary Addition - Practice 4
1. 101 + 11 =
2. 111 + 111 =
3. 1010 + 1010 =
4. 11101 + 1010 =
5. 11111 + 11111 =
Binary Multiplication 5
Binary, two 1-bit values
A B AB
0 0 0
0 1 0
1 0 0
1 1 1
Binary Multiplication 6
Binary, two n-bit values
As with decimal values
E.g., 1110
x 1011
1110
1110
0000
1110
10011010
Binary Multiplication - Practice 7
1002 x 0102 =
1112 x 0102 =
1102 x 0112 =
1012 x 0112 =
11102 x 00112 =
11012 x 01012 =
00102 x 11012 =
10102 x 11012 =
Signed Numbers 8
Up till now we've been concentrating on unsigned numbers. In real life we
have to represent signed numbers ( like: -12, -45, 78)
The difference between signed and unsigned numbers is the sign. A
method is required to represent the sign as part of the binary
representation
There are a number of schemes for representing signed numbers in binary
format
sign-magnitude representation
the twos-complement representation
Sign-Magnitude Representation 9
In this representation, the leftmost bit of a binary code
represents the sign of the value:
0 for positive
1 for negative
the remaining bits represent the numeric value
Sign-Magnitude Representation 10
To Compute negative values using Sign/Magnitude (signmag)
representation
Begin with the binary representation of the positive value, then flip
the leftmost zero bit
Sign-Magnitude Representation 11
Find the signmag representation of -610
Step1: find binary representation (8-bit)
610 = 000001102
Step2: if the number is a negative number flip left most bit
10000110
-610 = 100001102
Sign-Magnitude Representation 12
Find the signmag representation of -3610
Step 1: find binary representation
3610 = 001001002
Step 2: if the number is a negative number flip left most
bit
10100100
-3610 = 101001002
Sign-Magnitude Representation 13
Find the signmag representation of 7010
Step 1: find binary representation
7010 = 010001102
Step 2: if the number is a negative number flip left most
bit
01000110 (no flipping, since it is +ve)
7010 = 010001102
Sign-Magnitude Representation 14
What is this signmag number?
100011012
Google class room 15
Search google classroom
Then select join the classroom
Enter the code xqdds6r
Two’s Complement 16
Representation
Another scheme to represent negative numbers
The leftmost bit serves as a sign bit:
0 for positive numbers
1 for negative numbers
Two’s Complement 17
Representation
To Compute negative values using two’s Complement
representation, begin with the binary representation of the
positive value, complement (flip each bit if it is 0 make it 1 and
visa versa) the entire positive number, and then add one
Two’s Complement 18
Representation
Find the two’s complement representation of –610
Step1: find binary representation
610 = 000001102
Two’s Complement 19
Representation
Step 2: Complement the entire positive number, and then add
one
00000110
(complemented)-> 11111001
(add one) -> + 1
11111010
-610 = 111110102 (in 2's complement form)
Two’s Complement 20
Representation
Alternative method for step 2
Scan binary representation from right to left, find first one
bit, from low-order (right) end, and complement the
remaining pattern to the left
00000110
(left complemented) --> 11111010
Two’s Complement 21
Representation
Find the Two’s Complement of -7610
Step 1: Find the 8 bit binary representation of the positive
value
7610 = 010011002
Two’s Complement 22
Representation
Step 2:
Find first one bit, from low-order (right) end, and
complement the pattern to the left.
01001100
(left complemented) -> 10110100
-7610 = 101101002 (in 2's complement form)
Two’s Complement 23
Representation
Find the Two’s Complement of 7210
Step 1: Find the 8 bit binary representation of the positive
value.
7210 = 010010002
Two’s Complement 24
Representation
Step 2:
Since number is positive do nothing
So: 7210 = 010010002
why do we use 2's complement for signed 25
numbers
Two's complement allows negative and
positive numbers to be added together without
any special logic.
This means that subtraction and addition of both
positive and negative numbers can all be done by
the same circuit in the cpu
Why do we use 2’s complement for 26
subtraction
Two's complement is used because it is simpler to implement
in circuitry and also does not allow a negative zero.
The two's-complement system has the advantage of not
requiring that the addition and subtraction circuitry examine
the signs of the operands to determine whether to add or
subtract.
This property makes the system both simpler to implement
and capable of easily handling higher precision arithmetic.
References 27
http://www.wikihow.com/Add-Binary-Numbers
Introduction To Computer Science by ITL
Education Solutions Limited