Beruflich Dokumente
Kultur Dokumente
1 + 1 = 10 ?!?
Examples provided by
Jones & Bartlett Learning
Numbers
Natural Numbers
Zero and any number obtained by repeatedly adding one to it.
Negative Numbers
Values less than 0, indicated with a “–” sign before the left-most digit
Integers
Values that are either a natural number, or a negative number
Rational Numbers
Values that are integers, or the quotient of two integers
V
EECS1520: Representing Numbers 4
Abacus
amazon.com
Examples:
(642)10 = 6 * 102 + 4 * 101 + 2 * 100 = 642
(5073)8 = 5 * 83 + 0 * 82 + 7 * 81 + 3 * 80 = 2619
(1011)2 = 1 * 23 + 0 * 22 + 1 * 21 + 1 * 20 = 11
EECS1520: Representing Numbers 17
7
Non-Decimal Number Systems
What bases can these values be in? 122, 198, 178, G1A4
8 4 2 1
(23) (22) (21) (20)
EECS1520: Representing Numbers 19
8 4 2 1
(23) (22) (21) (20)
EECS1520: Representing Numbers 20
8 4 2 1
(23) (22) (21) (20)
EECS1520: Representing Numbers 21
8 4 2 1
(23) (22) (21) (20)
EECS1520: Representing Numbers 22
8 4 2 1
(23) (22) (21) (20)
EECS1520: Representing Numbers 23
8 4 2 1
(23) (22) (21) (20)
EECS1520: Representing Numbers 24
8 4 2 1
(23) (22) (21) (20)
EECS1520: Representing Numbers 25
8 4 2 1
(23) (22) (21) (20)
EECS1520: Representing Numbers 26
Binary Numbers and Computers
Low Voltage = 0
High Voltage = 1 all bits have 0 or 1
Byte
8 bits
• 32-bit machines
• 64-bit machines etc.
1 + 1 is 0 with a carry
Carry Values
1011111
1010111
+1 0 0 1 0 1 1
10100010
0110110100001100
0011011010000110
111 7 0011011010000110
110 6 Can be shortened by dividing the
101 5 number into 3-bit chunks,
starting from the least significant bit
100 4
and replacing each with a single
011 3 Octal digit
010 2
001 1
000 0
111 7 000011011010000110
110 6 0 3 3 2 0 6
101 5 Inserted to make a complete group of 3 bits
100 4
011 3
010 2
001 1
000 0
6 x 82 = 6 x 64 = 384
+ 4 x 81 = 4 x 8 = 32
+ 2 x 8º = 2 x 1 = 2
= 418 in base 10
= 𝑑𝑛−1 𝑑𝑛−2 ⋯ 𝑑1 𝑏 ∗ 𝑏 + 𝑑0
= 𝑑𝑛−1 𝑑𝑛−2 ⋯ 𝑑1 𝑏 × 𝑏 + 𝑑0
𝑄𝑢𝑜𝑡𝑖𝑒𝑛𝑡 𝑅𝑒𝑚𝑎𝑖𝑛𝑑𝑒𝑟
Try it!
Left to right
9 0
4 1
2 0
1 0
0 1
( 3 7 ) 10 = ( 1 0 0 1 0 1 ) 2
EECS1520: Representing Numbers 49
Converting Decimal to Octal
Try it!
Left to right
31 0
3 7
0 3
( 1988) 10 = ( 3704) 8
EECS1520: Representing Numbers 51
Converting Decimal to Hexadecimal
Try it!
222 15 = F
Left to right
13 14 = E
0 13 = D
( 3567) 10 = ( DEF) 16
EECS1520: Representing Numbers 53
Summary: base conversion methods
Sum scaled positional values
10 b
Repeated division by b
8 16
sign bit
0 101 = +5
1 101 = 5
0 000 = +0
1 000 = 0
• 0 has two different representations.
• How to eliminate this wasted redundancy and ambiguity?
3 2 1 0 ( bit positions )
−23 22 21 20 ( positional values )
1 1 0 1 ( the number )
= −23 ∗1 + 22 ∗ 𝟏 + 21 ∗ 𝟎 + 20 ∗ 𝟏
= −8 + 4 + 0 + 1
= −3
EECS1520: Representing Numbers 56
2’s Complement Notation
𝑛 bits e.g., 𝑛 = 8
MAX 01111111 = +2𝑛−1 − 1 = +127
01111110
…
00000010 = +2
00000001 = +1
00000000 = 0
11111111 = –1
11111110 = –2
…
MIN 10000000 = −2𝑛−1 = – 128
01111111
+ 00000011
10000010
Its value =
dn-1 bn-1 +dn-2 bn-2 +... +d1 b1 +d0 b0 + d-1 b-1 + d-2 b-2 + …
Examples:
(64.2)10 = 6 * 101 + 4 * 100 + 2 * 10-1 = 64.2
(50.73)8 = 5 * 81 + 0 * 80 + 7 * 8-1 + 3 * 8-2 = 40.921875
(10.11)2 = 1 * 21+ 0 * 20 + 1 * 2-1 + 1 * 2-2 = 2.75
EECS1520: Representing Numbers 63
7
Fractions: Binary to Decimal
21 20 2−1 2−2
Note:
Integer part: (1 0 )2 = 2
Fractional part: (. 1 1 )2 = .75
2 .7 5 10 = ? 2
𝟐 .𝟕 𝟓 𝟏𝟎 = 𝟏𝟎. 𝟏 𝟏 𝟐
+ .0023456 × 10+5
+ .023456 × 10+4
+ .23456 × 10+3 (“normalized”)
+ 2.3456 × 10+2
+ 23.456 × 10+1
+ 234.56 × 10+0
+ 2345.6 × 10-1
+ 23456. × 10-2
+ 234560. × 10-3
+ 53 2346
01101001
0 110 1001
sign exponent mantissa
Sign: positive
0 110 1001
sign exponent mantissa
Exponent:
• Excess-4 notation:
• 110 = 6 in decimal
• Subtract 4 from decimal value to recover the actual exponent
• 6 – 4 = +2
0 110 1001
sign exponent mantissa
Mantissa: .1001
0 110 1001
sign exponent mantissa
+ +2 .1001
sign-bit = 1
exponent = +3 = 111 in excess-4 (i.e., 3+4 = 7)
mantissa = 1101
Examples:
101.011 20 = .101011 23
11.01101 20 = .1101101 22
.001101 20 = .1101 2-2
• Round the mantissa to nearest 4 bits: keep the 4 leftmost bits; truncate the rest.
Round up if the 5th (now truncated) bit was 1 (otherwise don’t round up).
• Examples:
2’s Complement Excess Notation Decimal
011 111 3
101 001 3
010 110 2
110 010 2
EECS1520: Representing Numbers 82