Chapter 3 - Data - Representation
Chapter 3 - Data - Representation
Data
Representation
Numbers, Arithmetic
Operations and Characters
Computers are built using logic circuits, that
operate on information represented by 2
valued electrical signals ( 1 and 0).
Numbers --- binary number
Text character --- character code
Number representation
3 major representations for representing positive
and negative numbers:
Sign and magnitude
One’s complement
Two’s complement
-3 10 11 01 00 +4 1 100 = - 4
10 10 01 01
-2 +5 -
10 01 01 10
-1 10 00 01 11 +6
-0 +7
High order bit is sign: 0 = positive (or zero), 1 = negative
Three low order bits is the magnitude: 0 (000) thru 7 (111)
Number range for n bits = +/-2n-1 -1
Two representations for 0
One’s Complement
Representation
-0 +0
-1 11 11 00 00 +1
11 10 00 01
-2 +2 +
11 01 00 10
-3 11 00 00 11 +3 0 100 = + 4
-4 10 11 01 00 +4 1 011 = - 4
10 10 01 01
-5 +5 -
10 01 01 10
-6 10 00 01 11 +6
-7 +7
Subtraction implemented by addition & 1's complement
Still two representations of 0! This causes some problems
Some complexities in addition
Two’s Complement
Representation
-1 +0
-2 11 11 00 00 +1
11 10 00 01
-3 +2 +
like 1's comp 11 01 00 10
except shifted -4 11 00 00 11 +3 0 100 = + 4
one position
clockwise -5 10 11 01 00 +4 1 100 = - 4
10 10 01 01
-6 +5 -
10 01 01 10
-7 10 00 01 11 +6
-8 +7
Sign and
b 3 b 2 b1 b 0 magnitude 1's complement 2's complement
0 1 1 1 +7 +7 + 7
0 1 1 0 +6 +6 + 6
0 1 0 1 +5 +5 + 5
0 1 0 0 +4 +4 + 4
0 0 1 1 +3 +3 + 3
0 0 1 0 +2 +2 + 2
0 0 0 1 +1 +1 + 1
0 0 0 0 +0 +0 + 0
1 0 0 0 - 0 -7 - 8
1 0 0 1 - 1 -6 - 7
1 0 1 0 - 2 -5 - 6
1 0 1 1 - 3 -4 - 5
1 1 0 0 - 4 -3 - 4
1 1 0 1 - 5 -2 - 3
1 1 1 0 - 6 - 1 - 2
1 1 1 1 - 7 -0 - 1
(a) 0010 ( + 2)
+ 0011 ( + 3)
0101 ( + 5) (b) 0100 ( + 4)
+ 1010 (- 6)
(c) 1011 (- 5 )
+ 1110 ( - 2) 1110 (- 2)
(d) 0111 ( + 7)
1001 ( - 7)
+ 1101 ( - 3)
(e) 1101 (- 3 ) 0100 ( + 4)
- 1001 (- 7 )
1101
+ 0111
(f) 0010 ( + 2) 0100 ( + 4)
- 0100 ( + 4)
0010
+ 1100
(g) 0110 ( + 6) 1110 ( - 2)
- 0011 ( + 3) 0110
+ 1101
0011 ( + 3)
(h) 1001 ( - 7)
- 1011 ( - 5) 1001
+ 0101
1110 ( - 2)
(i) 1001 (- 7 )
- 0001 ( + 1) 1001
+ 1111
1000 ( - 8)
(j) 0010 ( + 2) 0010
- 1101 ( - 3) + 0011
0101 ( + 5)