0% found this document useful (0 votes)
129 views16 pages

Digital Design I: Lecture 1 - Binary Systems

Digital Design I covers binary systems and number representations. The key topics discussed are: 1) Binary numbers represent values using only the digits 0 and 1. Decimal numbers can be converted to binary and vice versa. 2) Other number systems like octal and hexadecimal use different radixes and allowed digits. 3) Complements are used to simplify subtraction in different bases. The 1's complement of a binary number is obtained by flipping all its bits.

Uploaded by

Berker Güngör
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
129 views16 pages

Digital Design I: Lecture 1 - Binary Systems

Digital Design I covers binary systems and number representations. The key topics discussed are: 1) Binary numbers represent values using only the digits 0 and 1. Decimal numbers can be converted to binary and vice versa. 2) Other number systems like octal and hexadecimal use different radixes and allowed digits. 3) Complements are used to simplify subtraction in different bases. The 1's complement of a binary number is obtained by flipping all its bits.

Uploaded by

Berker Güngör
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Digital Design I

Lecture 1 – Binary Systems

Asst. Prof. Dr. Ertuğrul SAATÇI

Binary Numbers
 A decimal number such as 7392 can be represented as:
7x103 + 3x102 + 9x101 + 2x100

 The convention is to write only the coefficients and from


their position deduce the necessary powers of 10.

 A number with a decimal point is represented by a series


of coefficients as follows:
a5 a4 a3 a2 a1 a0 . a-1 a-2 a-3

 This can be expressed as:


105a5+ 104a4+ 103a3+ 102a2+ 101a1+100a0+ 10-1a-1+
+10-2a-2+ 10-3a-3

1
Binary Numbers
 The coefficients of the binary numbers system have only
two possible values: 0 or 1.
• Each coefficient aj is multiplied by 2j.
• The digits in a binary number called bits.

 The decimal equivalent of the binary 11010.11 is 26.75


1x24 + 1x23 + 0x22 + 1x21 + 0x20 + 1x2-1 + 1x2-2 =
26.75
n 2n n 2n n 2n n 2n
1 2 5 32 9 512 13 8192
2 4 6 64 10 1024 14 16384
3 8 7 128 11 2048 15 32768
4 16 8 256 12 4096 16 65536

Binary Numbers
 In general, a number expressed in base-r system has
coefficients multiplied by powers of r:
an . rn + an-1 . rn-1 + . . . + a2 . r2 + a1 . r1 + a0 . r0 + a-1 .
r-1 + a-2 . r-2+ . . . + a-m . r-m
 The coefficients aj range in value from 0 to r-1.

System Radix Allowable Digits


Binary 2 0,1
Octal 8 0,1,2,3,4,5,6,7
Decimal 10 0,1,2,3,4,5,6,7,8,9
Hexadecimal 16 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F

Radix  the base number in a number system.


is the number of different digits allowed in that system.

2
Binary Numbers
 A number (in any system) can have an integer part and
fractional part separated with a radix point.

 (4021.2)5 = 4x53 + 0x52 + 2x51 + 1x50 + 2x5-1


= 4x125 + 0 + 10 + 1 + 2x(1/5)
= 500 + 11 + .4
= (511.4)10

 (B65F)16 = 11x163 + 6x162 + 5x161 + 15x160


= 11x4096 + 6x256 + 5x16 + 15
= 45056 + 1536 + 80 + 15
= (46687)10

Binary Numbers
 Arithmetic operations with numbers in base r follow the
same rules as for decimal numbers.
augend: 101101 minuend: 101101
addend: + 100111 subtrahend: - 100111
sum: 1010100 difference: 000110

multiplicand: 1011
multiplier: x 101
1011
0000
+ 1011
product: 110111

3
Number Base Conversions
 A binary number can be converted to decimal by forming
the sum of powers of 2 of those coefficients whose value
is 1.

(1010.011)2 = 23 + 21 + 2-2 + 2-3 = (10.375)10

 Similarly, a number expressed in base-r can be


converted to its decimal equivalent by multiplying each
coefficient with the corresponding power of r and adding.

(630.4)8 = 6x82 + 3x81 + 0x80 + 4x8-1 = (408.5)10

Number Base Conversions


 Conversion from Decimal 41 to Binary:

Integer quotient Remainder Coefficient


41/2 20 1 a0 = 1
20/2 10 0 a1 = 0
10/2 5 0 a2 = 0
5/2 2 1 a3 = 1
2/2 1 0 a4 = 0
1/2 0 1 a5 = 1

 The conversion from decimal integers to any base-r


system is similar to the example, except that division is
done by r instead of 2.

4
Number Base Conversions
 Conversion from Decimal 153 to Octal:

Integer quotient Remainder Coefficient


153/8 19 1 a0 = 1
19/8 2 3 a1 = 3
2/8 0 2 a2 = 2

153
19 1
2 3
0 2 = (231)8

Number Base Conversions


 Conversion from Decimal fraction (0.6875)10 to Binary:

Integer Fraction Coefficient


0.6875x2 1 0.3750 a-1 = 1
0.3750x2 0 0.7500 a-2 = 0
0.7500x2 1 0.5000 a-3 = 1
0.5000x2 1 0.0000 a-4 = 1

(0.6875)10 = (0.a-1a-2a-3a-4) = (0.1011)2


 The conversion from decimal fraction to any base-r
system is similar to the example. Multiplication is by r
instead of 2, and the coefficients found from the integers
may range in value from 0 to r-1 instead of 0 and 1.

5
Number Base Conversions
 Conversion from Decimal fraction (0.513)10 to Octal:
Integer Fraction Coefficient
0.513x8 4 0.104 a-1 = 4
0.104x8 0 0.832 a-2 = 0
0.832x8 6 0.656 a-3 = 6
0.656x8 5 0.248 a-4 = 5
0.248x8 1 0.984 a-5 = 1
0.984x8 7 0.872 a-6 = 7
... ... ... ...

(0.513)10 = (0.406517…)8

 The conversion of decimal numbers with both integers and


fraction parts is done by converting the integer and fraction
separately and then combining the two answers.

Octal and Hexadecimal Numbers


 The conversion from and to binary, octal and hexadecimal
plays an important part in digital computers.
 Since 23 = 8 and 24 = 16, each octal digit corresponds to
three binary digits and each hexadecimal digit corresponds
to four binary digits.

 Conversion from binary to Octal:


(10 110 001 101 011 . 111 100 000 110)2 = (26153.7406)8

 Conversion from binary to Hexadecimal:


(10 1100 0110 1011 . 1111 0000 0110)2 = (2C6B.F06)16

6
Octal and Hexadecimal Numbers
 Conversion from Octal to binary:
(673.124)8 = (110 111 011. 001 010 100)2

 Conversion from Hexadecimal to binary:


(306.D)16 = (0011 0000 0110 . 1101)2

 Conversion from Hexadecimal to Decimal:


(37B)16 =
= 3x162 + 7x161 + 11x160
= 3x256 + 7x16 + 11x1
= 768 + 112 +11
= (891)10

Complements
Diminished Radix Complement
 Complements are used to simplify the subtraction
operation and for logical manipulation.
 Given a number N in base-r having n digits, the (r–1)’s
complement of N is defined as (rn–1)–N.

 For decimal numbers, r=10 and r–1=9, so the 9’s


complement of N is (10n–1)–N.
 In this case, 10n represents a number that consists of a
single 1 followed by n zeros. 10n–1 is a number represented
by n 9s. If n=4 then 104=10000 and 104–1= 9999.
 The 9’s complement of 546700 is
(106–1)–546700 = 999999–546700 = 453299
 The 9’s complement of 012398 is
(106–1)–012398 = 999999-012398 = 987601

7
Complements
Diminished Radix Complement
 For binary numbers, r=2 and r–1=1, so the 1’s
complement of N is (2n–1)–N.
 2n is represented by a binary number that consists of a
single 1 followed by n zeros. If n=4 then 24=(10000)2 and
24–1=(1111)2.

 Therefore the 1’s complement of a binary number is


obtained by subtracting each digit from 1.

 Since subtracting binary digits from 1 causes the bit to


change from 0 to 1 or from 1 to 0.
 1-0=1 or 1-1=0
 The 1’s complement of a binary number is formed by
changing 1’s to 0’s and 0’s to 1’s.
 The 1’s complement of 1011000 is 0100111.
 The 1’s complement of 0101101 is 1010010.

Complements
Radix Complement
 The r’s complement of n digit number N in base r is
defined as rn–N for N≠0 and 0 for N=0.

 Comparing with the (r–1)’s complement, the r’s


complement is obtained by adding 1 to the (r–1)’s
complement since
rn–N = [(rn–1)–N] + 1.
 The 10’s complement of decimal 2389
(104–1) – 2389 + 1 = 7611.
 The 2’s complement of binary 101100
(26–1) – 101100 + 1 = 111111 – 101100 + 1 = 010100.

8
Complements
Radix Complement
 The 10’s complement of N can be formed by
• leaving all least significant 0’s unchanged,
• subtracting the first nonzero least significant digit from 10,
• and subtracting all higher significant digits from 9.
 The 10’s complement of decimal 012398
106 – 012398 = 987602.
 The 10’s complement of decimal 246700
106 – 246700 = 753300.

 Similarly, the 2’s complement of N can be formed by


• leaving all least significant 0’s and the first 1 unchanged,
• and replacing 1’s with 0’s and 0’s with 1’s in all other higher
significant digits.
 The 2’s complement of binary 1101100 is 0010100.
 The 2’s complement of binary 0110111 is 1001001.

Summary

System Radix Complement Diminished Radix Complement


Decimal r=10 10's complement 9's complement
Octal r=8 8's complement 7's complement
Binary r=2 2's complement 1's complement

 To find the radix complement representation of a number, it is more


convenient to first derive the diminished radix complement.
 The radix complement is then obtained by adding 1 to the diminished
radix complement.
• The 9's complement of a decimal number is obtained by subtracting
each digit from 9.
• The 7's complement of an octal number is obtained by subtracting
each digit from 7.
• The 1's complement of a binary integer is obtained by subtracting
each digit from 1.

9
Subtraction with Complements
 The direct method of subtraction uses borrow concept:
 A 1 is borrowed from a higher significant position when the
minuend digit is smaller than the subtrahend digit.

 If we consider the implementation of subtraction with


digital hardware, this method is less efficient than the
method that uses complements.

Subtraction with Complements


 The subtraction of two n digit numbers M-N in base r can
be done as follows:
• Add the minuend M to the r’s complement of the subtrahend
N.
M + (rn-N) = M – N + rn
• If M ≥ N the sum will produce an end carry rn which can be
discarded; what is left is the result M-N.
• If M < N the sum does not produce an end carry and is equal
to rn-(N-M), which is the r’s complement of (N-M).

10
Subtraction with Complements
Example 1
 Using 10’s complement, subtract 72532 – 3250

M= 72532
10’s complement of N = + 96750 (99999–03250)+1
----------
Sum = 169282
Discard end carry 10 = - 100000
5

----------
Answer = 69282

 The occurrence of the end carry signifies that M≥N and the
result is positive.

Subtraction with Complements


Example 2
 Using 10’s complement, subtract 3250 – 72532

M= 03250
10’s complement of N = + 27468 (99999–72532)+1
---------
Sum = 30718
There is no end carry
Therefore the answer is – (10’s complement of 30718)
Answer = – 69282

 When subtracting with complements, the negative answer is


recognized from the absence of the end carry and the
complemented result.

11
Subtraction with Complements
Example 3
 Given the two binary numbers X=1010100 and Y=1000011,
using 2’s complement perform X–Y and Y–X.

X= 1010100
2’s complement of Y = + 0111101
-------------
Sum = 10010001
Discard end carry 27 = - 10000000
-------------
Answer X-Y = 0010001

Subtraction with Complements


Example 3
 Given the two binary numbers X=1010100 and Y=1000011,
using 2’s complement perform X–Y and Y–X.

Y= 1000011
2’s complement of X = + 0101100
------------
Sum = 1101111
There is no end carry
The answer is – (2’s complement of 1101111)
Answer Y-X = - 0010001

12
Subtraction with Complements
Example 4
 Using 1’s complement perform X–Y and Y–X.
 Remember that the (r-1)’s complement is one less than the r’s
complement. Therefore the result is 1 less than the correct
difference when an end carry occurs.

X= 1010100
1’s complement of Y = + 0111100
-------------
Sum = 10010000
End-around carry = +1
-------------
Answer X-Y = 0010001
 Removing the end carry and adding 1 to the sum is referred to as an
end-around carry.

Subtraction with Complements


Example 4
 Using 1’s complement perform X–Y and Y–X.

Y= 1000011
1’s complement of X = + 0101011
------------
Sum = 1101110
There is no end carry
The answer is – (1’s complement of 1101110)
Answer Y-X = - 0010001

13
Signed Binary Numbers
Signed-Magnitude Convention
 In this convention, a binary number consists of a magnitude
and a symbol (+ or -) or a bit (0 or 1) indicating the sign.

 It is customary to represent the sign with a bit placed in the


leftmost position of the number and to make it 0 for positive and
1 for negative.

 Consider the number 9 represented in binary with 8 bits.


 +9 is represented with sign bit 0 in the leftmost position followed by
the binary equivalent of 9.
9  00001001 (unsigned binary)
+9  00001001 (signed binary)
-9  10001001 (signed binary)
137  10001001 (unsigned binary)

Signed Binary Numbers


Signed-Complement System
 In this system, a negative number is represented by its
complement.
 This system can use either the 1’s or the 2’s complement,
but 2’s complement is the most common.
 When arithmetic operations are implemented in a computer,
it is more convenient to use this system to represent
negative numbers.

 Consider the number 9 represented in binary with 8 bits.


 In signed-1’s complement, -9 is obtained by complementing
all the bits of +9, including the sign bit.
+9  00001001 (signed-magnitude representation)
-9  10001001 (signed-magnitude representation)
-9  11110110 (signed-1’s complement representation)
-9  11110111 (signed-2’s complement representation)

14
Example
All Possible 4-bit Signed Binary Numbers
Decimal Signed-2’s Complement Signed-1’s Complement Signed Magnitude
+7 0111 0111 0111
+6 0110 0110 0110
+5 0101 0101 0101
+4 0100 0100 0100
+3 0011 0011 0011
+2 0010 0010 0010
+1 0001 0001 0001
+0 0000 0000 0000
-0 - 1111 1000
-1 1111 1110 1001
-2 1110 1101 1010
-3 1101 1100 1011
-4 1100 1011 1100
-5 1011 1010 1101
-6 1010 1001 1110
-7 1001 1000 1111
-8 1000 - -

Signed Binary Numbers


Arithmetic Addition
 The addition of 2 numbers in the signed-magnitude
system follows the rules of ordinary arithmetic.
• If the signs are the same, add the two magnitudes and give
the sum the common sign.
• If the signs are different, subtract the smaller magnitudes
from the larger and give the result the sign of the larger
magnitude.
(+25) + (-37) = -(37-25) = -12

 This process requires the comparison of the signs and the


magnitudes and then performing either addition or
subtraction.

15
Signed Binary Numbers
Arithmetic Addition
 The rule for adding numbers in the signed-complement system
does not require a comparison or subtraction, but only addition.
 A carry out of the sign-bit position is discarded.
 If the sum obtained after the addition is negative, it is in 2’s
complement form.

+6 00000110 -6 11111010
+13 00001101 +13 00001101
+19 00010011 +7 00000111

+6 00000110 -6 11111010
-13 11110011 -13 11110011
-7 11111001 -19 11101101

Signed Binary Numbers


Arithmetic Subtraction
 Take the 2’s complement of the subtrahend (including the sign
bit) and add it to the minuend (including the sign bit).
 A carry out of the sign-bit position is discarded.
(± A) – (+B) = (± A) + (–B)
(± A) – (–B) = (± A) + (+B)

(–6)–(–13) = (11111010)–(11110011)
(–6)+(+13) = (11111010)+(00001101) = 00000111

-6 11111010
+13 00001101
+7 100000111 (remove the end carry)

16

You might also like