ECCE 210-Lect-2-3-NumberSystem
ECCE 210-Lect-2-3-NumberSystem
Learning objectives
• Review material covered mostly in computer
organization class
– Represent data in different digital formats:
• Positional number system
• Binary coded decimal (BCD)
• Hexadecimal systems
– Negative number representation
– Convert from one format to another
• Perform basic mathematical operations on data
represented in different format.
• Alphanumeric codes.
i 0
• Octal and Hex
K k n 1k n 2 k1k 0
n 1
V ( K ) ki r i
i 0
Quantities/Counting (1 of 3)
Hexa-
Decimal Binary Octal decimal
0 0 0 0
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
6 110 6 6
7 111 7 7
p. 233
Quantities/Counting (2 of 3)
Hexa-
Decimal Binary Octal decimal
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
Quantities/Counting (3 of 3)
Hexa-
Decimal Binary Octal decimal
16 10000 20 10
17 10001 21 11
18 10010 22 12
19 10011 23 13
20 10100 24 14
21 10101 25 15
22 10110 26 16
23 10111 27 17 Etc.
Decimal Octal
Binary Hexadecimal
pp. 230-234
Quick Example
Base
Decimal Octal
Binary Hexadecimal
Next slide…
Weight
Base
Binary to Decimal
Decimal Octal
Binary Hexadecimal
Binary to Decimal
• Technique
– Multiply each bit by 2n, where n is the “weight”
of the bit
– The weight is the position of the bit, starting
from 0 on the right
– Add the results
Example
Bit “0”
1010112 => 1 x 20 = 1
1 x 21 = 2
0 x 22 = 0
1 x 23 = 8
0 x 24 = 0
1 x 25 = 32
4310
Octal to Decimal
Decimal Octal
Binary Hexadecimal
Octal to Decimal
• Technique
– Multiply each bit by 8n, where n is the “weight”
of the bit
– The weight is the position of the bit, starting
from 0 on the right
– Add the results
Example
7248 => 4 x 80 = 4
2 x 81 = 16
7 x 82 = 448
46810
Hexadecimal to Decimal
Decimal Octal
Binary Hexadecimal
Hexadecimal to Decimal
• Technique
– Multiply each bit by 16n, where n is the
“weight” of the bit
– The weight is the position of the bit, starting
from 0 on the right
– Add the results
Example
Decimal to Binary
Decimal Octal
Binary Hexadecimal
Decimal to Binary
• Technique
– Divide by two, keep track of the remainder
– First remainder is bit 0 (LSB, least-significant
bit)
– Second remainder is bit 1
– Etc.
Example
12510 = ?2 2 125
2 62 1
2 31 0
2 15 1
2 7 1
2 3 1
2 1 1
0 1
12510 = 11111012
Octal to Binary
Decimal Octal
Binary Hexadecimal
Octal to Binary
• Technique
– Convert each octal digit to a 3-bit equivalent
binary representation
Example
7058 = ?2
7 0 5
7058 = 1110001012
Hexadecimal to Binary
Decimal Octal
Binary Hexadecimal
Hexadecimal to Binary
• Technique
– Convert each hexadecimal digit to a 4-bit
equivalent binary representation
Example
10AF16 = ?2
1 0 A F
10AF16 = 00010000101011112
Decimal to Octal
Decimal Octal
Binary Hexadecimal
Decimal to Octal
• Technique
– Divide by 8
– Keep track of the remainder
Example
123410 = ?8
8 1234
8 154 2
8 19 2
8 2 3
0 2
123410 = 23228
Decimal to Hexadecimal
Decimal Octal
Binary Hexadecimal
Decimal to Hexadecimal
• Technique
– Divide by 16
– Keep track of the remainder
Example
123410 = ?16
16 1234
16 77 2
16 4 13 = D
0 4
123410 = 4D216
Binary to Octal
Decimal Octal
Binary Hexadecimal
Binary to Octal
• Technique
– Group bits in threes, starting on right
– Convert to octal digits
Example
10110101112 = ?8
1 3 2 7
10110101112 = 13278
Binary to Hexadecimal
Decimal Octal
Binary Hexadecimal
Binary to Hexadecimal
• Technique
– Group bits in fours, starting on right
– Convert to hexadecimal digits
Example
10101110112 = ?16
10 1011 1011
2 B B
10101110112 = 2BB16
Octal to Hexadecimal
Decimal Octal
Binary Hexadecimal
Octal to Hexadecimal
• Technique
– Use binary as an intermediary
Example
10768 = ?16
1 0 7 6
2 3 E
10768 = 23E16
Hexadecimal to Octal
Decimal Octal
Binary Hexadecimal
Hexadecimal to Octal
• Technique
– Use binary as an intermediary
Example
1F0C16 = ?8
1 F 0 C
1 7 4 1 4
1F0C16 = 174148
Exercise –Answer
Convert …
Hexa-
Decimal Binary Octal decimal
33 100001 41 21
117 1110101 165 75
451 111000011 703 1C3
431 110101111 657 1AF
Binary Addition (1 of 2)
• Two 1-bit values
A B A+ B
0 0 0
0 1 1
1 0 1
1 1 10
“two”
pp. 234-
240
ECCE 210 Digital Logic Design Slide 51
Lecture 2-3: Number Systems
Binary Addition (2 of 2)
• Two n-bit values
– Add individual bits
– Propagate carries
– E.g.,
1 1
10101 21
+ 11001 + 25
101110 46
Multiplication (1 of 3)
• Decimal (just for fun)
35
x 105
175
000
35
3675
Multiplication (2 of 3)
• Binary, two 1-bit values
A B AB
0 0 0
0 1 0
1 0 0
1 1 1
Multiplication (3 of 3)
• Binary, two n-bit values
– As with decimal values
– E.g.,
1110
x 1011
1110
1110
0000
1110
10011010
Fractions
• Decimal to decimal (just for fun)
Fractions
• Binary to decimal
10.1011 => 1 x 2-4 = 0.0625
b1b0 .b1b2 b31
b4 x 2-3 = 0.125
0 x 2-2 = 0.0
1 x 2-1 = 0.5
0 x 20 = 0.0
1 x 21 = 2.0
2.6875
Fractions
• Decimal to binary x
.14579
2
3.14579 0.29158
x 2
0.58316
x 2
1.16632
x 2
0.33264
x 2
0.66528
x 2
1.33056
11.001001... etc.
Exercise –Answer
Convert …
Hexa-
Decimal Binary Octal decimal
29.8 11101.110011… 35.63… 1D.CC…
5.8125 101.1101 5.64 5.D
3.109375 11.000111 3.07 3.1C
12.5078125 1100.10000010 14.404 C.82
Signed Integers
• Previous examples were for “unsigned
integers” (positive values only!)
• Must also have a mechanism to represent
“signed integers” (positive and negative
values!)
• E.g., -510 = ?2
• Two common schemes: sign-magnitude
and twos complement
Sign-Magnitude
• Extra bit on left to represent sign
– 0 = positive value
– 1 = negative value
• E.g., 6-bit sign-magnitude representation
of +5 and –5:
+5: 0 0 0 1 0 1 -5: 1 0 0 1 0 1
+ve 5 -ve 5
Ranges (revisited)
Binary
Unsigned Sign-magnitude
No. of bits Min Max Min Max
1 0 1
2 0 3 -1 1
3 0 7 -3 3
4 0 15 -7 7
5 0 31 -15 15
6 0 63 -31 31
Etc.
ECCE 210 Digital Logic Design Slide 64
Lecture 2-3: Number Systems
In General (revisited)
Binary
Unsigned Sign-magnitude
No. of bits
Min Max Min Max
n 0 n n-1
2 - 1 -(2 - 1) 2 - 1
n-1
Complementary
Representations
• 1’s complement
• 2’s complement Next slides
Twos Complement
• Most common scheme of representing negative
numbers in computers
• Affords natural arithmetic (no special rules!)
• To represent a negative number in 2’s
complement notation…
1. Decide upon the number of bits (n)
2. Find the binary representation of the +ve value in n-bits
3. Flip all the bits (change 1’s to 0’s and vice versa)
4. Add 1
Sign Bit
• In 2’s complement notation, the MSB is
the sign bit (as with sign-magnitude
notation)
0 = positive value
1 = negative value
+5: 0 0 0 1 0 1 -5: 1 1 1 0 1 1
“Complementary” Notation
• Conversions between positive and
negative numbers are easy
• For binary (base 2)…
2’s C
+ve -ve
2’s C
Example
+5 0 0 0 1 0 1
1 1 1 0 1 0
2’s C
+ 1
-5 1 1 1 0 1 1
0 0 0 1 0 0
2’s C
+ 1
+5 0 0 0 1 0 1
Exercise – 2’sAnswer
C conversions
• What is -20 expressed as an 8-bit binary
number in 2’s complement notation?
– Answer: 1101100
Ranges (revisited)
Binary
No. of Unsigned Sign-magnitude 2’s complement
bits
Min Max Min Max Min Max
1 0 1
2 0 3 -1 1 -2 1
3 0 7 -3 3 -4 3
4 0 15 -7 7 -8 7
5 0 31 -15 15 -16 15
6 0 63 -31 31 -32 31
Etc.
ECCE 210 Digital Logic Design Slide 76
Lecture 2-3: Number Systems
In General (revisited)
Binary
No. of Unsigned Sign-magnitude 2’s complement
bits
Min Max Min Max Min Max
n 0 n n-1
2 - 1 -(2 - 1) 2 -1 -2
n-1 n-1
2
n-1
-1
Sign-magnitude Twos-complement
11 1 1 1 1 11
-5: 10000101 -5: 11111011
+5: +00000101 +5: +00000101
10001010 00000000
A – B = A + (-B)
What is 10 subtract 3?
• 7, of course, but…
• Let’s do it (we’ll use 6-bit values)
10 – 3 = 10 + (-3) = 7
+3: 000011
1s C: 111100
+1: 1 001010
-3: 111101 +111101
000111
-3: 111101
1s C: 000010
+1: 1 001010
+3: 000011 +000011
001101
( + 5) 0101 ( –5 ) 1011
+ ( –2 ) + 1110 + ( –2 ) + 1110
( + 3) 1 0011 ( –7 ) 1 1001
ignore ignore
The result is always correct since a carry from the sign-bit can be simply ignored.
This is not true for 1’s complement.
Alphanumeric Data
• There are four standards for representing
letters (alpha) and numbers
– BCD – Binary-coded decimal Next 2 slides
– ASCII – American standard code for information
interchange
– EBCDIC – Extended binary-coded decimal
interchange code
– Unicode
Example
• 709310 = ? (in BCD)
7 0 9 3
The Problem
• Representing text strings, such as
“Hello, world”, in a computer
ASCII Features
• 7-bit code
• 8th bit is unused (or used for a parity bit)
• 27 = 128 codes
• Two general types of codes:
– 95 are “Graphic” codes (displayable on a
console)
– 33 are “Control” codes (control features of
the console or communications channel)
ASCII Chart
In General (binary)
Binary
No. of bits
Min Max
n 0 2n - 1