CH 01
CH 01
Sheis Abolmaali
School of ECE
Semnan University
1
Binary Numbers 1/2
• Internally, information in digital systems is of
binary form
– groups of bits (i.e. binary numbers)
– all the processing (arithmetic, logical, etc) are
performed on binary numbers.
• Example: 4392
– In decimal, 4392 = …
– Convention: write only the coefficients.
– A = a1 a0 . a-1 a-2 a-3 where aj {0, 1, …, 9}
– How do you calculate the value of A?
2
Binary Numbers 2/2
• Decimal system
– coefficients are from {0,1, …, 9}
– and coefficients are multiplied by powers of 10
– base-10 or radix-10 number system
• Using the analogy, binary system {0,1}
– base(radix)-2
• Example: 25.625
– 25.625 = decimal expansion
– 25.625 = binary expansion
– 25.625 =
3
Base-r Systems
• base-r (n, m)
– A = an-1 rn-1 +… + a1 r1 + a0 r0 + a-1 r-1 + a-2 r-2 + … +a-m r-m
• Octal
– base-8 = base-23
– digits {0,1, …, 7}
– Example: (31.5)8 = octal expansion =
• Hexadecimal
– base-16
– digits {0, 1, …, 9, A, B, C, D, E, F}
– Example:
– (19.A)16 = hexadecimal expansion =
4
Powers of 2
• 210 = 1,024 (K) -
• 220 = 1,048,576 (M) -
• 230 (G) -
• 240 (T) -
• 250 (P) -
• exa, zetta, yotta, … (exbi, zebi, yobi, ...)
• Examples:
– A byte is 8-bit, i.e. 1 B
– 16 GiB = ? B = 17,179,869,184
5
Arithmetic with Binary Numbers
0 0 1 0 multiplicand (2)
1 0 1 1 multiplier (11)
0 0 1 0
0 0 1 0
0 0 0 0
+ 0 0 1 0
0 0 1 0 1 1 0 product (22)
6
Multiplication with Octal Numbers
3 4 5 229 multiplicand
6 2 1 401 multiplier
3 4 5
7 1 2
+ 2 5 3 6
2 6 3 2 6 5 91829 product
7
Base Conversions
• From base-r to decimal is easy
– expand the number in power series and add all the
terms
• Reverse operation is somewhat more difficult
• Simple idea:
– divide the decimal number successively by r
– accumulate the remainders in the remainder
• If there is a fraction, then integer part and
fraction part are handled separately.
8
Base Conversion Examples 1/3
• Example 1:
– 55
– (decimal to binary)
– Example 2:
– 144
– (decimal to octal)
9
Base Conversion Examples 2/3
• Example 1: 0.6875 (decimal to binary)
– When dealing with fractions, instead of dividing by r
multiply by r until we get an integer
– …
10
Base Conversion Examples 2/3
• We are not always this lucky
• Example 2: (144.478) to octal
– Treat the integer part and fraction part separately
– 0.4788 = 3.824 = 3 + 0.824 a-1 = 3
– 0.8248 = 6.592 = 6 + 0.592 a-2 = 6
– 0.5928 = 4.736 = 4 + 0.736 a-3 = 4
– 0.7368 = 5.888 = 5 + 0.888 a-4 = 5
– 0.8888 = 7.104 = 7 + 0.104 a-5 = 7
– 0.1048 = 0.832 = 0 + 0.832 a-6 = 0
– 0.8328 = 6.656 = 6 + 0.656 a-7 = 6
– 144.478 = (220.3645706…)8
11
Conversions between Binary, Octal
and Hexadecimal
• r = 2 (binary), r = 8 (octal), r = 16 (hexadecimal)
10110001101001.101100010111
13
How to Complement?
• A number N in base-r (n-digit)
1. rn – N r’s complement
2. (rn-1) – N (r-1)’s complement
– where n is the number of digits we use
• Example: r = 2, n = 4, N = 7
– rn = 24 = 16, rn -1 = 15.
– 2’s complement of 7 ?
– 1’s complement of 7 ?
• Easier way to compute 1’s and 2’s complements
– Use binary expansions
– 1’s complement: negate
– 2’s complement: negate + increment
14
Subtraction with Complements 1/4
• Conventional subtraction
– Borrow concept
– If the minuend digit is smaller than the subtrahend
digit, you borrow “1” from a digit in higher significant
position
• With complements
– M-N = ?
– rn – N r’s complement of N
– M + (rn – N) =
15
Subtraction with Complements 2/4
• M + (rn – N) = M – N + rn
1. if M N,
– the sum will produce a carry, that can be discarded
2. Otherwise,
– the sum will not produce a carry, and will be equal to
rn – (N-M), which is the r’s complement of N-M
16
Subtraction with Complements 3/4
• Example:
– X = 1010100 (84) and Y = 1000011 (67)
– X-Y = ? and Y-X = ?
X 1010100
2’s complement of Y + 0111101
10010001
Y 1000011
2’s complement of X + 0101100
1101111
-0010001
17
Subtraction with Complements 4/4
• Example: Previous example using 1’s complement
X 1010100
1’s complement of Y + 0111100
Y 1000011
1’s complement of X + 0101011
18
Signed Binary Numbers
• Pencil-and-paper
– Use symbols “+” and “-”
• We need to represent these symbols using bits
– Convention:
• 0 positive
1 negative
• The leftmost bit position is used as a sign bit
– In signed representation, bits to the right of sign bit
is the number
– In unsigned representation, the leftmost bit is a part
of the number (i.e. the most significant bit (MSB))
19
Signed Binary Numbers
• Example: 5-bit numbers
– 01011 ? (unsigned binary)
– ? (signed binary)
– 11011 ? (unsigned binary)
– ? (signed binary)
– This method is called “signed-magnitude” and is rarely
used in digital systems (if at all)
• In computers, a negative number is represented
by the complement of its absolute value.
• Signed-complement system
– positive numbers have always “0” in the MSB position
– negative numbers have always “1” in the MSB position
20
Signed-Complement System
• Example:
– 11 = (01011)
– How to represent –11 in 1’s and 2’s complements
1. 1’s complement –11 = ?
2. 2’s complement -11 = ?
– If we use eight bit precision:
– 11 = 00001011
– 1’s complement -11 = ?
– 2’s complement -11 = ?
21
Signed Number Representation
Signed magnitude One’s complement Two’s complement
000 +0 000 +0 000 0
001 +1 001 +1 001 +1
010 +2 010 +2 010 +2
011 +3 011 +3 011 +3
100 -0 111 -0 111 -1
101 -1 110 -1 110 -2
110 -2 101 -2 101 -3
111 -3 100 -3 100 -4
25
Arithmetic Overflow 2/2
• Example:
+2 0010 -3 1101
+4 + 0100 -5 + 1011
+7 0111 -3 1101
+6 + 0110 -6 + 1010
-6 11111010 -6 11111010
-13 - 11110011 +
x y AND OR NOT
x·y x + y x’
0 0
0 1
1 0
1 1
33
Logic Gates
• Binary values are represented as electrical
signals
– Voltage, current
• They take on either of two recognizable values
– For instance, voltage-operated circuits
– 0V 0
– 4V 1
• Electronic circuits that operate on one or more
input signals to produce output signals
– AND gate, OR gate, NOT gate
34
Range of Electrical Signals
• What really matters is the range of the signal
value
35
Logic Gate Symbols
36
Gates Operating on Signals
V
x 0 1 1 0 0
t
y 0 0 1 1 0
t
AND: xy 0 0 1 0 0
t
OR: xy 0 1 1 1 0
t
NOT: x’ 1 0 0 1 1
t
Input-Output Signals for gates
Gates with More Than Two Inputs
38