chap1
chap1
Alan B. Marcovitz
◦ Third Edition
◦ McGraw Hill
◦ 2010
Numerical Representations
• In science, technology, business and other
fields, we deal with quantities.
• Quantities are measured, monitored, recorded,
manipulated arithmetically and observed in
most physical systems
• It is important when dealing with various
quantities that we be able to represent their
values efficiently and accurately
40
30 Analog signal
20
10
40
30
20 Digital signal
10
-V
Human sound Voltage signal
Store Analog to
digital
0 1 0 1 1 0 converter
Arithmetic/
Logic
5V
Binary 1
2V 1 1
Not used 4V
0.8 V
Binary 0 0 0
0V 0V t
t1 t2 t3 t4 t5
f = 1/200x10-9 = 109/200
= 5x106 = 5 MHz
• Bit Numbering
7 6 5 4 3 2 1 0
1 0 0 1 1 1 0 1
27 26 25 24 23 22 21 20
Some common
powers of 2
Binary number system Example
• 1011.1012 = 1 x 23 + 0 x 22 + 1 x 21 + 1 x 20 +
1 x 2-1 + 0 x 2-2 + 1 x 2-3
= 8 + 0 + 2 + 1 + 0.5 + 0 + 0.125
= 11.62510
1 0 1 1 . 1 0 1
Binary
MSB LSB
point
ELEC 335, DIGITAL LOGIC DESIGN, UAE
UNIVERSITY
Binary Counting
23 = 8 22 = 4 21 = 2 20 = 1
0 0 0 0
0 0 0 1
0 0 1 0
0 10 100 1000
0 0 1 1
1 11 101 1001
0 1 0 0
0 1 0 1
110 1010
0 1 1 0 111 1011
0 1 1 1 1100
1 0 0 0 1101
1 0 0 1 1110
1 0 1 0 1111
1 0 1 1
1 1 0 0
1 1 0 1
1 1 1 0
1 1 1 ELEC 335,
1 DIGITAL LOGIC DESIGN, UAE
UNIVERSITY
Decimal Binary
Number Number
Binary Numbers 0 0000
1 0001
A binary counting sequence for numbers from zero to 2 0010
fifteen is shown. 3 0011
4 0100
Notice the pattern of zeros and ones in each 5 0101
column.
6 0110
Digital counters frequently have this same pattern of 7 0111
digits: 8 1000
9 1001
Counter 0 1 0 1 0 1 0 1 0 1 Decoder
10 1010
0 0 1 1 0 0 1 1 0 0
11 1011
12 1100
0 0 0 0 1 1 1 1 0 0
13 1101
0 0 0 0 0 0 0 0 1 1
14 1110
15 1111
Start by writing the column weights; then add the weights that
correspond to each 1 in the number.
= 48 + 4 + 0 + 2/4 + 3/16
= 52.6875
ELEC 335, DIGITAL LOGIC DESIGN, UAE
UNIVERSITY
Hexadecimal numbers
• In a hexadecimal system there are 16 different
digits, namely, 0 to 9 and A, B, C, D, E, and F
C 6 F . 5
copy
To convert a hex number to binary
binary, perform the opposite point
operation
ELEC 335, DIGITAL LOGIC DESIGN, UAE
UNIVERSITY
Octal number system
• The octal number system has a base of eight, that
means it has eight different digits, namely, 0, 1, 2,
3, 4, 5, 6, and 7
• To convert an octal number to decimal, simply
multiply each digit by the corresponding power of
eight
• Ex: 3728 = 3 x 82 + 7 x 81 + 2 x 80
= 3 x 64 + 7 x 8 + 2 x 1
= 25010
ELEC 335, DIGITAL LOGIC DESIGN, UAE
UNIVERSITY
Converting Octal & Hex to Decimal
Octal to Decimal: N8 = (dn-1 × 8n-1) +... + (d1 × 8) + d0
Examples:
5 6 7 . 4 2
copy
binary
point
ELEC 335, DIGITAL LOGIC DESIGN, UAE
UNIVERSITY
Octal number to binary number
• To convert from octal to binary, simply expand
each octal digit into 3 binary digits
• Ex: convert 436.57 to binary
9 1 5
• To convert a decimal number to BCD, simply take
each decimal digit and expand it to its binary
• Ex: convert 874 to BCD
◦ Uses 1 byte for ASCII, but multiple bytes for other characters
Null-terminated String
◦ Array of characters followed by a NULL character
Printable ASCII Codes
0 1 2 3 4 5 6 7 8 9 A B C D E F
2 space ! " # $ % & ' ( ) * + , - . /
3 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
4 @ A B C D E F G H I J K L M N O
5 P Q R S T U V W X Y Z [ \ ] ^ _
6 ` a b c d e f g h i j k l m n o
7 p q r s t u v w x y z { | } ~ DEL
Examples:
ASCII code for space character = 20 (hex) = 32 (decimal)
ASCII code for 'L' = 4C (hex) = 76 (decimal)
ASCII code for 'a' = 61 (hex) = 97 (decimal)
Gray code
Binary sequence
Gray code sequence
X 0 0 1 1
+Y +0 +1 +0 +1
CS 00 01 01 10
Adding three bits: the sum is S and the carry is C
0 0 0 0 1 1 1 1
0 0 1 1 0 0 1 1
+0 +1 +0 +1 +0 +1 +0 +1
00 01 01 10 01 10 10 11
Binary Addition
Start with the least significant bit (rightmost bit)
carry 1 1 1 1
0 0 1 1 0 1 1 0 (54)
+ 0 0 0 1 1 1 0 1 (29)
0 1 0 1 0 0 1 1 (83)
bit position: 7 6 5 4 3 2 1 0
Addition in base-b
• The rules of addition remain the same for base-b
• Consider additions in base-2 (binary) and base-16(hex)
011 0 11
1001 A2CE
0011 + B963 +
1 10 0 15C3 1
X 0 0 1 1
–Y –0 –1 –0 –1
BD 00 -1 1 01 00
Subtracting two bits (X – Y) with a borrow-in = -1: we get the difference (D)
and the borrow-out (B)
borrow-in -1 -1 -1 -1 -1
X 0 0 1 1
–Y –0 –1 –0 –1
BD -1 1 -1 0 00 -1 1
Binary Subtraction
Start with the least significant bit (rightmost bit)
Subtract each pair of bits
Include the borrow in the subtraction, if present
borrow -1 -1 -1
0 0 1 1 0 1 1 0 (54)
– 0 0 0 1 1 1 0 1 (29)
0 0 0 1 1 0 0 1 (25)
bit position: 7 6 5 4 3 2 1 0
Binary Multiplication
Binary Multiplication table is simple:
0×0=0, 0×1=0, 1×0=0, 1×1=1
Multiplicand 11002 = 12
Multiplier × 11012 = 13
Binary multiplication is easy
1100
0000 0 × multiplicand = 0
1100 1 × multiplicand = multiplicand
1100
Product 100111002 = 156
n-bit multiplicand × n-bit multiplier = 2n-bit product
Accomplished via shifting and addition
Hexadecimal Addition
Start with the least significant hexadecimal digits
Let Sum = summation of two hex digits
If Sum is greater than or equal to 16
◦ Sum = Sum – 16 and Carry = 1
Example:
carry 1 1 1
9 C 3 7 2 8 6 5
+ 5 + B = 5 + 11 = 16
1 3 9 5 E 8 4 B Since Sum ≥ 16
Sum = 16 – 16 = 0
A F C D 1 0 B 0 Carry = 1
Multiplication in base-b
• The rules of multiplication remain the same
• Consider multiplication in base-2 and base-16
1001
0101 x
1001
0000 Add
1001
0000
0101101
ELEC 335, DIGITAL LOGIC DESIGN, UAE
UNIVERSITY
Multiplication in base-16
201
1C2A
12B 3 x
5 4 7E
135CE Add
3854
1C2A
20EA55E
The 1’s complement of a binary number is just the inverse of the digits. To
form the 1’s complement, change all 0’s to 1’s and all 1’s to 0’s.
1 1 0 0 1 0 1 0
0 0 1 1 0 1 0 1
0 0 1 1 0 1 0 1
Input bits
Carry
Adder
in (add 1)
Output bits (sum)
0 0 1 1 0 1 1 0
There are several ways to represent signed binary numbers. In all cases, the
MSB in a signed number is the sign bit, that tells you if the number is positive
or negative.
Rules for addition: Add the two signed numbers. Discard any final carries. The
result is in signed form.
Examples:
Note that if the number of bits required for the answer is exceeded,
overflow will occur. This occurs only if both numbers have the same sign.
The overflow will be indicated by an incorrect sign bit.
0001 0011
0001 0011 0111 Final result
ELEC 335, DIGITAL LOGIC DESIGN, UAE
UNIVERSITY
BCD