Digital Logic Design
Chapter 1:
Digital Systems and Binary Numbers
1
Conversion between bases
• To convert from one base to other:
– Convert the integer portion
– Convert the fraction portion
– Join the two with radix point
Octal (base 8)
Binary (base 2) Decimal (base 10)
Hexadecimal
(base16)
Radix point is the symbol used to separate the integer part of a number from its fractional
part.
• Convert the integer portion
r-Decimal Conversion • Convert the fraction portion
• Join the two with radix point
• Conversion of a number in base r to decimal is done by
expanding the number in a power series and adding all the
terms.
• For example, (C34D)16 is converted to decimal:
12 X 163 + 3 X 162 + 4 X 161 + 13 X 160 = (49997)10
• (11010.11)2 is converted to decimal:
1 X 24 + 1 X 23 + 0 X 22 + 1 X 21 + 0 X 20 + 1 X 2-1 + 1 X 2-2 = 26.75
• In general (Number)r = i n 1
i 0
ai r i
j 1
a
j m j
r j
(Integer Portion) + (Fraction Portion)
Radix point is the symbol used to separate the integer part of a number from its fractional
part.
Decimal-r Conversion
• If a decimal number has a radix point, it is necessary to separate
the number into an integer part and a fraction part.
• The conversion of a decimal integer into a number in base-r is
done by dividing the number and all successive quotients by r
and accumulating the remainders in reverse order of
computation.
• For example, to convert decimal 13 to binary:
Integer
Remainder Coefficient
Quotient
13/2 = 6 + 1 a0 = 1
6/2 = 3 + 0 a1 = 0
3/2 = 1 + 1 a2 = 1
1/2 = 0 + 1 a3 = 1
Answer (13)10 = (a3 a2 a1 a0)2 = (1101)2
Decimal-r Conversion
• Convert (37)10 to binary
(37)10 = 100101
Decimal-r Conversion (converting fraction)
• To convert the fraction portion repeatedly multiply the fraction by
the radix and save the integer digits that result. The process
continued until the fraction becomes 0 or the number of digits
have sufficient accuracy. The new radix fraction digits are the
integer digits in computed order.
• For example convert fraction (0.6875)10 to base 2
0.6875 * 2 = 1.3750 integer = 1
0.3750 * 2 = 0.7500 integer = 0
0.7500 * 2 = 1.5000 integer = 1
0.5000 * 2 = 1.0000 integer = 1
Answer = (0.1011)2
Decimal-r Conversion (converting fraction)
• When converting fractions, we must use multiplication
rather than division. The new radix fraction digits are
the integer digits in computed order.
Decimal-r Conversion (converting fraction)
• Convert 0.8125 decimal to
binary.
– To convert the decimal
0.8125 to binary, we
multiply by the radix 2.
– (0.1101)2
Decimal to Octal Conversion
• In converting decimal to octal we must divide by 8.
Converting Fractions (Decimal to Octal)
• Decimal to Octal fraction conversion takes the same approach
but it multiplies by the base 8.
Converting Decimal to Hexadecimal
• The conversion of a decimal integer into hexadecimal is done by
dividing the number and all successive quotients by 16 and
accumulating the remainders in reverse order of computation.
(422)10 = (1A6)16
Binary, Octal and Hexadecimal
• Conversions between binary, octal and hexadecimal have an
easier conversion method.
– Each octal digit represents 3 binary digits.
– Each hexadecimal digit represents 4 binary digits.
– Example: convert 11010101111111.10111001)2 into Octal and Hexadecimal
numbers
(011 010 101 111 111.101 110 010)2 = (32577.562)8
3 2 5 7 7 5 6 2
(0011 0101 0111 1111.1011 1001)2 = (357F.B9)16
3 5 7 F B 9
Binary to Octal and back
• Binary to Octal:
– Group the binary digits into three bit groups starting at the
radix point and going both ways, padding with zeros as
needed (at the ends).
– Convert each group of three bits to an equivalent octal digit.
• Octal to Binary:
– It is done by reversing the preceding procedure
– Restate the octal as three binary digits
– Start at the radix point and go both ways, padding with zeros
as needed.
Examples
• Convert (10110001101011.11110000011)2 to Octal
= 010 110 001 101 011 . 111 100 000 110
= 2 6 1 5 3 . 7 4 0 6
= (26153.7406)8
• Convert (673.124)8 to binary
= 110 111 011 . 001 010 100
= (110111011.001010100)2
• Convert (11010100011011) 2
to Octal
Binary to Hexadecimal and back
• Binary to Hexadecimal:
– Group the binary digits into four bit groups starting at the radix point and
going both ways, padding with zeros as needed (at the ends)
– Convert each group of four bits to an equivalent hexadecimal digit
• Hexadecimal to Binary:
– It is done by reversing the preceding procedure
– Restate the hexadecimal as four binary digits
– Start at the radix point and go both ways, padding with zeros as needed
Examples
• Convert (10110001101011.11110010)2 to hexadecimal
= 0010 1100 0110 1011 . 1111 0010
= 2 C 6 B . F 2
= (2C6B.F2)16
• Convert (306.D)16 to binary
= 0011 0000 0110. 1101
= (001100000110.1101)2
• Convert (11010100011011) 2
to hexadecimal
Base-r Arithmetic
• Arithmetic operations with numbers in base r follow the same rules as
for decimal numbers.
• When a base other than 10 is used, one must remember to use only the
r-allowable digits.
• The sum of two digits are calculated as expected but the digits of the
sum can only be from the r-allowable coefficients.
• Any carry in a sum is passed to the next significant digits to be
summed.
• In subtraction the rules are the same but a borrow adds r (where r is the
base) to the minuend digit.
• The following are some examples:
Binary Addition
Given two binary digits (X,Y), a carry in (Z) we get the
following sum (S) and carry (C):
Carry in (Z) of 0: Z 0 0 0 0
X 0 0 1 1
+Y +0 +1 +0 +1
CS 00 01 01 10
Carry in (Z) of 1: Z 1 1 1 1
X 0 0 1 1
+Y +0 +1 +0 +1
CS 01 10 10 11
Binary Addition --Examples
carry: 1
0 0 0 0 0 1 0 0 (4)
+ 0 0 0 0 0 1 1 1 (7)
0 0 0 0 1 0 1 1 (11)
bit position: 7 6 5 4 3 2 1 0
1 1 1 1 1 1 carries
1 1 1 1 0 1
+ 1 0 1 1 1
---------------------
1 0 1 0 1 0 0
Binary Subtraction
• Subtraction Table
0-0=0
0 - 1 = 1 and borrow 1
• The borrow process works: 1-0=1
1 10 borrows
1 - 10
0 10 10 = 0 0 10
1 0 0 1 1 0 1
- 1 0 1 1 1
------------------------
1 1 0 1 1 0
Binary Multiplication and Division
• Multiplication table
1 0 1 1 1
X 1 0 1 0
0x0=0 -----------------------
0 0 0 0 0
0x1=0 1 0 1 1 1
0 0 0 0 0
1x0=0 1 0 1 1 1
-----------------------
1x1=1 1 1 1 0 0 1 1 0
• Binary division is similar to decimal division
Why Complements ?
• Problems for Computers
– Take borrow
– Dealing with sign (+ or -)
– Dealing with carry
• Complements are used to simplify subtraction operations. We do
subtraction by adding.
A – B = A+ (-B)
• There are two types:
– The radix complement, called the r’s complement.
– The diminished radix complement, called the (r-1)’s complement.
Diminished Radix Complement (DRC)
• Given a number N in base r having n digits, the (r-1)’s complement of N is
defined as:
(rn – 1) – N
• Decimal numbers are in base-10.
(r-1) = (10-1) = 9.
• The 9’s complement would be defined as:
(10n – 1) – N
• So, to determine the 9’s complement of 52:
(102 – 1) – 52 = 47
• The DRC or (r-1)’s complement of decimal number is obtained by subtracting
each digit from 9
• The (r-1)’s complement of octal or hexadecimal number is obtained by
subtracting each digit from 7 or F, respectively
• The DRC (1’s complement) of a binary number is obtained by subtracting each
digit from 1. It can also be formed by changing 1’s to 0’s and 0’s to 1’s
DRC for Binary Numbers
• The DRC (1’s complement) of a binary number is obtained by subtracting each
digit from 1. It can also be formed by changing 1’s to 0’s and 0’s to 1’s
• Given a number N in base r having n digits, the (r-1)’s complement of N is
defined as:
(rn – 1) – N
• For binary numbers r = 2 and (r-1) = 1. So, the 1’s complement would be
defined as:
(2n – 1) – N
• To determine the 1’s complement of 1000101:
(27 – 1) – 1000101 = 0111010
• Note that 1’s complement can be done by switching all 0’s to 1’s and 1’s to 0’s.
Radix Complement
• The r’s complement of an n-digit number N in base-r is defined
as:
rn – N - for N 0
0 - for N = 0
• We may obtain r’s complement by adding 1 to (r-1)’s
complement. Since rn – N = [(rn – 1) – N]+1
• 10’s complement of 3229 is:
104 – 3229 = 6771
• 2’s complement of 101101 is:
26 – 101101 = 010011
• Note that to determine 2’s complement, leave the least
significant 0’s and the first 1 unchanged and then switch the
remaining 1’s to 0’ and 0’s to 1’s.
2’s Complement
• Another method to find 2’s complement is
– Complement (reverse) each bit
– Add 1
• Example:
Note that 00000001 + 11111111 = 00000000
Notes on Complements
– Complements used to avoid borrow as computers cannot do it
– Computers can not deal with signs, so complements can help
– If you are trying to determine the complement of a value that contains a radix
point:
» Remove the radix point.
» Determine the complement.
» Replace the radix point in the same relative position.
– The complement of a complement will restore the original number
– Radix or r’s Complement are 2’s, 8’s, 10’s or 16’s complements
– DRC or r-1)’s Complement are 1’s, 7’s, 9’s or 15’s complements
– For signed magnitude system,
» 1’s complement used for Logical Operations
» 2’s complement used for negative numbers
Summary of Complements
• You can Calculate :
– 1’s complement by changing 1’s to 0’s and 0’s to 1’s
– 9’s complement by subtracting each digit from 9
– 7’s complement by subtracting each digit from 7
– F’s complement by subtracting each digit from 15
– 2’s complement by leaving all LSB 0s an the first 1 unchanged and replace all 1’s to
0’s and 0’s to 1’s
– 10’s complement by leaving all LSB 0sunchanged, subtract first non- zero digit from
10 and rest all digits from 9
– 10’s complement by adding 1 to 9’s complement