cs303 ch1 BinarySystems
cs303 ch1 BinarySystems
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)
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
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
If there is a fraction, then integer part and fraction part
are handled separately.
Base Conversion Examples 1/3
Example 1:
55
(decimal to binary)
Example 2:
144
(decimal to octal)
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
0.6875×2 = 1.375 1
0.375 ×2 = 0.750 0
0.750×2 = 1.5 1
0.5×2 = 1.0 1
0.6875 = (0.1011)2
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.478×8 = 3.824 = 3 + 0.824 a-1 = 3
0.824×8 = 6.592 = 6 + 0.592 a-2 = 6
0.592×8 = 4.736 = 4 + 0.736 a-3 = 4
0.736×8 = 5.888 = 5 + 0.888 a-4 = 5
0.888×8 = 7.104 = 7 + 0.104 a-5 = 7
0.104×8 = 0.832 = 0 + 0.832 a-6 = 0
0.832×8 = 6.656 = 6 + 0.656 a-7 = 6
144.478 = (220.3645706…)8
Conversions between Binary, Octal and
Hexadecimal
r = 2 (binary), r = 8 (octal), r = 16 (hexadecimal)
10110001101001.101100010111
M-N M + (rn – N)
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
Since M – N + rn = rn – (N-M)
Subtraction with Complements 3/4
Example:
X = 1010100 (84) and Y = 1000011 (67)
X-Y = ? and Y-X = ?
X 10101
2’s complement of Y + 00
01111
01
100100
01
Y 10000
2’s complement of X + 11
01011
00
011011
11
Subtraction with Complements 4/4
Example: Previous example using 1’s complement
Signed Binary Numbers
Pencil-and-paper
Use symbols “+” and “-”
We need to represent these symbols using bits
Convention:
0 positive1 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))
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
Signed-Complement System
Example:
11 = (01011)
How to represent –11 in 1’s and 2’s complements
1’s complement - 11 = 10100
2’s complement - 11 = 10101
If we use eight bit precision:
11 = 00001011
1’s complement -11 = 11110100
2’s complement -11 = 11110101
Signed Number Representation
+ 011 - 110
7+ + 1
011 3- + 1
101
6 0 6 0
Rule: If the MSB and the bits to the left of it differ, then
there is an overflow
Subtraction with Signed Numbers
Rule: is the same
We take the 2’s complement of the subtrahend
It does not matter if the subtrahend is a negative number.
(±A) - (-B) = ±A+B
x y AND OR NOT
x·y x+y x’
0 0 0 0 1
0 1 0 1 1
1 0 0 1 0
1 1 1 1 0
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
Logic Gate Symbols
Logic Gate Symbols
NOT TRANSFER
AND XOR
O XNOR
R
NAND
NOR
Range of Electrical Signals
What really matters is the range of the signal value
Gates Operating on Signals
V
x 0 1 1 0 0
t
y 0 0 1 1 0
t
AND: 0 0 1 0 0
xy t
OR: 0 1 1 1 0
xy t
NOT: 1 0 0 1 1
x’ t
Input-Output Signals for
gates
Gates with More Than Two Inputs