Professional Documents
Culture Documents
1 Numberrepresentation
1 Numberrepresentation
Spring 2011
1. Number Representation
• 10 digits = {0,1,2,3,4,5,6,7,8,9}
4 5 3 7 . 8
3 2 1 0 -1
x 10 x 10 x 10 x 10 x 10
• 2 digits = {0,1}
1 0 1 1 . 1
3 2 1 0 -1
x 2 x 2 x 2 x 2 x 2
8 + 0 + 2 + 1 + .5 = (11.5) 10
Number systems: Base 8 (Octal)
• 8 digits = {0,1,2,3,4,5,6,7}
• example: (2365.2)
8
2 3 6 5 . 2
3 2 1 0 -1
x 8 x 8 x 8 x 8 x 8
• 16 digits = {0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F}
2 6 B A
3 2 1 0
x 16 x 16 x 16 x 16
• True = 1, False = 0
• “Hi there” = 72, 105, 32, 116, 104, 101, 114, 101
MSB LSB
e.g., 1001110111000101
value BCD
0 000
1 001
2 010
3 011
4 100
5 101
6 110
7 111
Addition of binary (unsigned numbers)
Like decimal addition, except:
1+1 = 0 with a carry of 1,
1+1+1 = 1 with carry of 1
e.g., wordsize = 5, add 11110 and 10101 (30 + 21)
Overflow 1 1 1
when result cannot fit 11110 30
within the wordsize + 21
constraint 10101
1 0 0 1 1 19
e.g., the “correct” answer
110011 requires 6 bits: cannot
be represented with only 5
bits in unsigned representation
What about negative numbers?
Given a fixed wordsize how do you represent both positive and negative
numbers?
Note: in 1’s complement, there are two ways to represent 0: all 0s and all 1s
Negative Numbers: 2’s Complement Representation
Note: negation works both ways in all cases except 1 followed by all 0s (e.g., 1000).
for wordsize=k, the value is -2k-1 (e.g., k=4, value is -8)
Note: the positive value of 2k-1 is not expressible
Number encoding summary
• signed mag: -2k-1 + 1 to 2k-1 - 1 (e.g., k=8, -127 to 127 [2 vals for 0])
• 2’s complement: -2k-1 to 2k-1 - 1 (e.g., k=8, -128 to 127 [1 val for 0])
Getting representation
• Observe:
• 2’s-complement operation negates a number when in 2’s-complement
representation
001110 001110
- +
101011
negate subtrahend (2’s complement op)
010101
111001
0
• X+Y still shifts bits (Y in BCD) slots clockwise
-1 000 1
111 001
• e.g., 2-3 = 010+101 = 010 shifted 5 slots
clockwise = 111 = -1 -2 110 010 2
01101100
0110.1100
2 1 -1 -2
2 + 2 + 2 + 2 = 6.75
• The number of integer and fraction bits must be agreed upon by those
generating and those reading the number.
Floating-Point Notation
5 exponent
• A lot like scientific notation: 5.4 x 10
mantissa
• Ones compliment
• Twos compliment
Sign and magnitude
0 000 3 000 1
1 001 1 001 1
2 010 2 011 1
3 011 1 010 1
4 100 3 110 1
5 101 1 111 1
6 110 2 101 1
7 111 1 100 1
How about letters?