Python 6

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

1s and 2s Complement

Section A

Dr. Emmanuel S. Pilli


Associate Professor, CSE
Number System
 A computer can understand the positional number system
where there are few symbols called digits.
 These symbols represent different values depending on the
position they occupy in the number.
 The value of each digit in a number can be determined using:
 The digit
 The position of the digit in the number
 The base of the number system
 The base is defined as the total number of digits available in
the number system
Signed Magnitude Method
 An extra sign bit is added to recognize negative and positive
numbers. Sign bit has 1 for negative number and 0 for
positive number.
Signed Magnitude Method
 Signed representation has an ambiguous representation of
number 0, two different representations: -0 and +0
1s Complement Method
 MSB is always the Sign bit. If it 0, then there are no changes.
 MSB is always 1 in case of negative numbers, then take 1’s
complement of number to represent it.
1s Complement Method
 1s Complement Method has an ambiguous representation of
number 0, two different representations: -0 and +0
2s Complement Method
 MSB is always the Sign bit. If it is 0, then there are no changes.
 MSB is always 1 in case of negative numbers, then take 2’s
complement of number to represent it.
2s Complement Method
 There is only one representation of +0 and -0, so the 2’s
complement representation is better
Comparison – Three Forms
Bits Binary Signed 1s C 2s C
3 0-7 -3 to +3 -3 to +3 -4 to +3
4 0-15 -7 to +7 -7 to +7 -8 to +7
5 0-31 -15 to +15 -15 to +15 -16 to +15
6 0-63 -31 to +31 -31 to +31 -32 to +31
7 0-127 -63 to +63 -63 to +63 -64 to +63
8 0-255 -127 to +127 -127 to +127 -128 to +127
12 0-4192 -2047 to +2047 -2047 to +2047 -2048 to +2047
16 0-65535 -32767 to +32767 -32767 to +32767 -32768 to +32767
Comparison – Three Forms
 Decimal 5 and Binary 101 represented using different
number of bits
Bits Binary Signed 1s C 2s C
3 101 1 101 1 010 1 011
4 0101 1 0101 1010 1011
5 00101 1 00101 11010 1 1011
6 000101 1 000101 111010 11 1011
7 0000101 1 0000101 1111010 111 1011
8 0000 0101 1 0000 0101 1111 1010 1111 1011
Comparison – Three Forms
No Binary Neg No Signed 1s C 2s C
3 011 -3 111 100 101
5 0101 -5 1101 1010 1011
12 1100 -12 1 1100 1 0011 1 0100
17 10001 -17 1 10001 1 01110 1 01111
25 11001 -25 1 11001 1 00110 1 00111
30 11110 -30 1 11110 1 00001 1 00010
33 100001 -33 1 100001 1 011110 1 011111
69 1000101 -69 1 1000101 1 0011 1010 1 0011 1011
Comparison – Three Forms
Neg
No Binary Signed 1s C 2s C
No
+119 0111 0111 -119 1111 0111 1000 1000 1000 1001
+127 0111 1111 -127 1111 1111 1000 0000 1000 0001
+128 1000 0000 -128 1 1000 0000 1 0111 1111 1 1000 0000
+229 1110 0101 -229 1 1110 0101 1 0001 1010 1 0001 1011
+255 1111 1111 -255 1 1111 1111 1 0000 0000 1 0000 0001
+256 1 0000 0000 -256 11 0000 0000 10 1111 1111 11 0000 0000
+457 1 1100 1001 -459 11 1100 1001 10 0011 0110 10 0011 0111

You might also like