BinaryNumSyst 1 PDF
BinaryNumSyst 1 PDF
One’s complement
One’s complement
Two’s complement
(35)10 = (100011)2 or
simply write 100011
(35)10 = (100011)2 or
simply write 100011
Algorithm
Start
1. Read x
2. Process q = x/2 (Note x/2 returns the quotient)
3. Process r = x%2 (Note x%2 returns the remainder)
4. Store r
Algorithm
Start
1. Read x
2. Process q = x/2 (Note x/2 returns the quotient)
3. Process r = x%2 (Note x%2 returns the remainder)
4. Store r
5. if (q = 0) then Goto Step7
6. else
6.1 Assign x = q
6.2 Goto Step2
7. print r values from last to fist.
Stop
0+0 = 0
0+1 = 1
1+0 = 1
1 + 1 = 10
0+0 = 0
0+1 = 1
1+0 = 1
1 + 1 = 10
Conceptually similar to
decimal addition
Addition rules:
0−0 = 0
0 − 1 = 1 barrow 1
1−0 = 1
1−1 = 0
Barrow 1 is equivalent to 2
Conceptually similar to
decimal addition Example (Subtract binary
Addition rules:
number 101 from 1011)
0−0 = 0
0 − 1 = 1 barrow 1
1−0 = 1
1−1 = 0
Barrow 1 is equivalent to 2
Conceptually similar to
decimal addition Example (Subtract binary
Addition rules:
number 101 from 1011)
0−0 = 0
0 − 1 = 1 barrow 1
1−0 = 1
1−1 = 0
Barrow 1 is equivalent to 2
Example (Sign-Magnitude)
we represent 6 as 0110 and −1 as 1001.
Example (Sign-Magnitude)
we represent 6 as 0110 and −1 as 1001.
But, we can see the following:
6 + (−1) = 5
But, 0110 + 1001 = 1111, that is, −7
Example (Sign-Magnitude)
we represent 6 as 0110 and −1 as 1001.
But, we can see the following:
6 + (−1) = 5
But, 0110 + 1001 = 1111, that is, −7
So, addition is not straightforward if the signs of the two numbers are
different.
Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 January 17, 2020 18 / 29
One’s complement
Flipping the bits
Example
For example, one’s complement of 0110(6) is 1001(−6).
6 + (−6) = 0
But, 0110 + 1001 = 1111 is equivalent to (−8)
Dr. Odelu Vanga (BITS-Pilani Hyderabad) CS F111 January 17, 2020 19 / 29
Two’s complement
We can see,
4 + (−4) = 0
0100 + 1100 = 0000
Next class..
Floating point data representation
Hexadecimal and Octal Number System
Thank You