You are on page 1of 64

DIGITAL LOGIC DESIGN

TOPIC 1
DIGITAL SYSTEMS AND BINARY NUMBERS

FAHIMUL HAQUE (FHE)


DEPT. OF ELECTRICAL & COMPUTER ENGINEERING

* Slides are used as an aiding tool to teach in the classroom. Not every
information/details that will be taught in the classes are mentioned on the slides.
Hence, you are expected to follow the given textbook(s) for your course.
Digital Systems are everywhere!
• Digital Communication Systems.
• Transportation of information in digital electronic form.
• HDTV, digital satellite radio, etc.
• Mobile phone technology: iPhones, Androids, etc.
• The Internet!
• Computer Systems.
• Calculators, PCs, parallel computing and
supercomputers.
• Games consoles (PlayStation 4, Xbox One, Wii U).
• Microcontrollers and embedded systems.
- FHE
• Consumer electronics.
– Audio recordings on CDs stored as 16-bit signed integers,
44.1 KHz sample rate.
– iPods, MP3 players.
– DVDs, Blu-Ray, 4K discs. Podcasts, video on demand.
– Smart phones, Handheld and mobile GPS systems.
• Digital signal processing systems.
– Extracting useful information from digitized electric signals.
– Remote sensing, satellite technology.
– Solar system exploration (e.g., the moon, asteroids, all of
the planets).
– Advanced robotics, autonomous vehicles.

- FHE
TWO WAYS OF NUMERICAL REPRESENTATION
OF A QUANTITY: ANALOG VS. DIGITAL
• Real-world “Analog” signals.
In the real world of electrical systems, electrical quantities such as
voltage and current are continuous-level as a function of
continuous-time, i.e., analog data can vary over a continuous range
of values.

This might be part of a speech or music waveform as produced by a microphone.


- FHE
• Digital-world signals (e.g., on a music CD).
In the digital world, such a voltage or current signal would be
represented with discrete levels and discrete time. Digital
quantities can take on only discrete values (0 and 1, high and low)

Thus, on a CD, the music is represented as a sequence of integers:


{4635, 4419, 4234, 897, -1344, -2873, ….}
- FHE
DIGITAL AND ANALOG SYSTEM
• A digital system is a combination of devices
designed to manipulate logical information or
physical quantities that are represented in digital
form; that is, the quantities can take on only
discrete values.
• Some of the familiar digital systems include
digital computers and calculators, digital audio
and video equipment, and the telephone
system—the world’s largest digital system.

- FHE
DIGITAL AND ANALOG SYSTEM
• An analog system contains devices that manipulate
physical quantities that are represented in analog
form. In an analog system, the quantities can vary
over a continuous range of values.
• Some common analog systems are old radios, audio
amplifiers etc.

- FHE
ADVANTAGE OF USING DIGITAL SYSTEM

❖ Digital devices are programmable and changing the program


can
perform new function in the same hardware and thereby cost
effective and economical.
❖ The advances in the fabrication technology make this product
extremely cheap and fast.
❖ The reliability of the devices is also good by using error
detecting
and correcting codes.
❖ Easier to design
❖ Easier information storage
- FHE
LIMITATION OF DIGITAL TECHNOLOGY

❖ The real world is mainly analog

❖ Processing digitized signals takes time.

- FHE
Solution: Back and forth between digital and analog signals
We must be able to convert analog voltages to numbers, and
also convert numbers back to analog voltages.

- FHE
DIGITAL NUMBER SYSTEM
• Many number systems are in use in digital technology.

• A number system defines a set of values used to represent


quantity, which in turns help us to make sense of our
environment.

• The most common are the decimal, binary, octal, and


hexadecimal systems. These are base 10, base 2, base 8, and
base 16 number systems, respectively.

• The decimal system is clearly the most familiar to us because it


is a tool that we use every day.

- FHE
NUMBER SYSTEMS AND CODES
Digital Systems are built from circuits that process binary digits.
But very few real-life problems are based on binary numbers.

So a digital system designer must establish some


correspondence between the binary digits processed by digital
circuits and real-life numbers, events and conditions.

- FHE
INFORMATION REPRESENTATION
▪ Elementary storage units inside computer can be considered as electronic
switches. Each switch holds one of two states: on (1) or off (0).

ON OFF

▪ We use a bit (binary digit), 0 or 1, to represent the state.


▪ Storage units (or bits) can be grouped together to cater for larger range
of numbers. Example: 2 bits to represent 4 values/combinations.
Decimal Binary
0 00
1 01
2 10
3 11
- FHE
INFORMATION REPRESENTATION

▪ In general, N bits can represent 2N different values.


▪ For M values, log 2 𝑀 bits are needed.

1 bit → represents up to 2 values (0 or 1)


2 bits → rep. up to 4 values (00, 01, 10 or 11)
3 bits → rep. up to ?
4 bits → rep. up to ?
32 values → requires ? Bits (Ans: 5 bits)
64 values → requires ? bits
1024 values → requires ? bits
40 values → requires ? bits
100 values → requires ? bits

- FHE
The Decimal Number System
• The primary number system used is a base ten number system.
• Base 10 number systems are called decimal number systems.
Ten digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9.
• Positional value may be stated as a digit multiplied by a power of 10.

104
106 105 103 102 101 100 10-110-210
-3 9735.2 =(9 * 103)
+ (7 * 102)
+ (3 * 101)
+ (5 * 100)
+ (2 * 10-1)

- FHE
General Rule of Number Representation
A number in base (also known as radix) r contains r digits: 0, 1, 2, . .
., r -1, and is expressed as a power series in r with the general form:
a3a2a1a0 . a-1a-2= a3*r3 + a2*r2 + a1*r1 + a0*r0 + a-1*r-1 + a-2*r-2

where, aj : Coefficients/Digits (aj is multiplied by weights rj )


j : Positional value
‘.’: is known as radix point.

* In decimal (base 10) number system, the coefficients aj are any of the 10
digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. Also, radix point is known as decimal point.

- FHE
Different Number Systems
➢ Octal Number System (base 8): Number system with only
eight numerals : 0, 1, 2, 3, 4, 5, 6, 7

➢ Hexadecimal Number System (base 16): Number system


with sixteen numerals : 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 , A, B, C, D, E, F

➢ Binary Number System (base 2): Number system with only


two numerals : 0 and 1. Digital computer manipulates discrete
elements of information and that all information in the computer
is represented in binary form.

- FHE
IMPORTANT FACT
• The more compact representation of binary numbers in either octal or
hexadecimal is much more convenient for people than using bit strings
in binary that are three or four times as long. Thus, most computer
manuals use either octal or hexadecimal numbers to specify binary
quantities.

• For example, a group of 15 bits can be represented in the octal system


with only 5 digits. A group of 6 bits can be represented in hexadecimal
with 4 digits.

- FHE
Number Conversion
From any base or Radix r to Decimal or base 10:

A number expressed in base or Radix r system can be


converted to Decimal by applying the following formula:

i= 0 to n  (a i r i) +
j= 1 to m (a j r -j)

ai : digits left to the radix point


aj : digits right to the radix point

- FHE
Example : Base-r to Decimal Conversion
Octal to Decimal
(127.4)8 = 1x82 + 2x81 + 7x80 + 4x8-1 = (87.5)10

Binary to Decimal
(110101)2 = 1x25 + 1x24 + 0x23 + 1x22 + 0x21 + 1x20 = (53)10
Base-5 to Decimal
(4021.2)5 = 4x53 + 0x52 + 2x51 + 1x50 + 2x5-1 = (511.4)10

* To distinguish between numbers of different bases, it is customary


to enclose the coefficients in parentheses and place a subscript after
the right parenthesis to indicate the base of the number.

- FHE
EXERCISE!
Convert Hexadecimal number (B65F)16 to Decimal number

Hexadecimal Decimal
0 to 9 0 to 9
A 10
B 11
C 12
D 13
E 14
F 15

- FHE
• Solution:

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


= (46687)10

- FHE
Converting Decimal integer to any Base-r
General Rule:
▪ Simply repeat dividing the number and all successive quotients
by r and saving the remainder

▪ First remainder will be the fast digit from right, Second


remainder will be the second digit from the right ….. and so
on

- FHE
Converting Decimal to Binary

▪ Simply repeat dividing by 2 and saving the remainder.


▪ First remainder will be the last digit in the binary number, second
remainder will be the second digit from the right; ….. and so on

Step Divide Equals Remainder Digits

(1) 105 / 2 = 52 1 1
(2) 52 / 2 = 26 0 01
(3) 26 / 2 = 13 0 001
(4) 13 / 2 = 6 1 1001
(5) 6/2= 3 0 01001
(6) 3/2= 1 1 101001
(7) 1/2= 0 1 1101001
So 105 in decimal is written as 1101001 in binary.
- FHE
Converting Decimal to Octal

▪ Simply repeat dividing by 8 and saving the remainder.


▪ First remainder will be the last digit in the octal number
▪ Second remainder will be the second digit from the right;
….. and so on.
Step Divide Equals Remainder Digits
(1) 3034 / 8 = 379 2 2
(3) 379 / 8 = 47 3 32
(5) 47 / 8 = 5 7 732
(6) 5/8= 0 5 5732

So, 3034 in decimal is written as 5732 in Octal

- FHE
Converting Decimal to Hex

▪ Simply repeat dividing by 16 and saving the remainder.


▪ First remainder will be the last digit in the octal number
▪ Second remainder will be the second digit from the right;
….. and so on.
Conversion of 16242 from decimal to hex

Step Divide Equals Remainder Digits

(1) 16242 / 16 = 1015 2 = 2 (hex) 2


(2) 1015 / 16 = 63 7 = 7 (hex) 72
(3) 63 / 16 = 3 15 = F (hex) F72
(4) 3 / 16 = 0 3 = 3 (hex) 3F72

So 16242 in decimal is written as 3F72 in hex.

- FHE
Converting Decimal fraction number to Base-r

General Rule:

▪ Simply repeat multiplying the number and all


successive fractions by r and saving the integer parts.

▪ These integer parts will be the coefficient of the


Base-r number

▪ First integer will be the fast digit from left after the
radix point, Second integer will be the second digit
from the left after radix point ….. and so on

- FHE
Converting Decimal fraction number to Base-r
Example: convert (0.6875)10 to binary Base-2
Integer Fraction Coefficient

0.6875 x 2 = 1.3750 1 + 0.3750 a-1 = 1

0.3750 x 2 = 0.7500 0 + 0.7500 a-2 = 0

0.7500 x 2 = 1.5000 1 + 0.5000 a-3 = 1

0.5000 x 2 = 1.000 1 + 0.000 a-4 = 1

(0.6875)10 = (0.1011)2

- FHE
Conversion of Decimal number with radix point to Base-r
▪Separate the integer and fraction part
▪Convert the integer and fraction point to Base-r number
separately
▪Combining the two answer
Example : conversion of (105.6875)10 to Binary
Separate the Integer and Fraction parts
(105.6875)10 = (105)10 + (0.6875)10

Convert Integer and Fraction part to Base-r number


separately
(105)10 = (1101001)2 as discussed before
(0.6875)10 = (1011)s as discussed before

Combining the two answers radix point


(105.6875)10 = (1101001.1011)2
- FHE
Converting Between Hex, Octal and Binary
Decimal (base 10) Binary (base 2) Octal (base 8) Hexadecimal (base 16)
00 0000 00 0
01 0001 01 1
02 0010 02 2
03 0011 03 3
04 0100 04 4
05 0101 05 5
06 0110 06 6
07 0111 07 7
08 1000 10 8
09 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F - FHE
Converting from Binary to Octal
▪Simply by taking the binary digits in groups of three
(from right to left) and converting to each group to
Octal.

Consider the binary number


10110100111100101101001011

If we take the digits in groups of three from right to left


and convert, we get:

10 110 100 111 100 101 101 001 011


2 6 4 7 4 5 5 1 3
(10110100111100101101001011)2 is (264745513)8 - FHE
Converting from Octal to Binary

Since each octal digit can be expressed in


exactly three binary digits, all we have to do is
convert each octal digit to three binary digits.

Converting 7563021 in octal to binary goes as


follows:

7 5 6 3 0 2 1
111 101 110 011 000 010 001

So (7563021)8 is (111101110011000010001)2 - FHE


Converting from Binary to Hex

▪Hex is base 16 and 16 is 24. That is, it takes exactly four


binary digits to make a hex digit

▪By taking binary digits in groups of four (right to left) we


can convert binary to hex.

▪Consider once more the binary number


10110100111100101101001011. By grouping in fours and
converting, we get:

10 1101 0011 1100 1011 0100 1011


2 D 3 C B 8 B

So 10110100111100101101001011 (binary)
= (2D3CB8B)16 (hex)
= (264745513)8 (octal) - FHE
Converting from Hex to Binary

Simply write each hex digit as four binary digits.

In this way we can convert 6F037C2:

6 F 0 3 7 C 2
0110 1111 0000 0011 0111 1100 0010

Since we can drop the leading zero,

(6F037C2)16 is (110111100000011011111000010)2.

- FHE
SIGNED BINARY NUMBERS

▪ There are three common ways of representing signed numbers


(positive and negative numbers) for binary numbers:
❖Sign-and-Magnitude
❖1s Complement

❖2s Complement

It is more convenient to use complement system for arithmetic operations


when the operations are implemented in a computer.

- FHE
SIGN-AND-MAGNITUDE
▪ Negative numbers are usually written by writing a minus sign in front.
❖Example:
- (12)10 , - (1100)2

▪ In computer memory of fixed width, this sign is usually represented by a bit:


0 for +
1 for -

- FHE
SIGN-AND-MAGNITUDE
▪ Example: an 8-bit number can have 1-bit sign and 7-bits
magnitude.

sign magnitude

- FHE
SIGNED MAGNITUDE
▪ Largest Positive Number: 0 1111111 +(127)10
▪ Largest Negative Number: 1 1111111 -(127)10
▪ Zeroes: 0 0000000 +(0)10
1 0000000 -(0)10
▪ Range: -(127)10 to +(127)10
▪ Signed numbers needed for negative numbers.
▪ Representation: Sign-and-magnitude.

- FHE
1’s Complement
▪ Given a number x which can be expressed as an n-bit binary number, its
negative value can be obtained in 1’s-complement representation using:
- x => 2n - x - 1

Example: With an 8-bit number 00001100, its negative value, expressed in


1’s complement, is obtained as follows:
-(00001100)2 = - (12)10
=> (28 - 12 - 1)10
= (243)10
= (11110011)1s

- FHE
1’s Complement
▪ Essential technique: invert all the bits.

Examples: 1’s complement of 00000001 = (11111110)1s


1’s complement of 01111111 = (10000000)1s

▪ Largest Positive Number: 0 1111111 +(127)10


▪ Largest Negative Number: 1 0000000 -(127)10
▪ Zeroes: 0 0000000
1 1111111

▪ Range: -(127)10 to +(127)10


▪ The most significant bit still represents the sign:
0 = +ve; 1 = -ve.

- FHE
1’s Complement

▪ Examples (assuming 8-bit binary numbers):


(14)10 = (00001110)2 = (00001110)1s
-(14)10 = -(00001110)2 = (11110001)1s
-(80)10 = -( ? )2 = (?)1s
-(80)10 = (01010000)2 = (10101111)1s

- FHE
2’s Complement
▪ Given a number x which can be expressed as an n-bit binary number, its
negative number can be obtained in 2’s-complement representation using:
- x = 2n - x

Example: With an 8-bit number 00001100, its negative value in 2s


complement is thus:
-(00001100)2 = - (12)10
= (28 - 12)10
= (244)10
= (11110100)2s

- FHE
2’s Complement
▪ Essential technique: invert all the bits and add 1.
Examples:
2s complement of
-(00000001)2 = (11111110)1s (invert)
= (11111111)2s (add 1)
2s complement of
-(01111110)2 = (10000001)1s (invert)
= (10000010)2s (add 1)

* Similarly, the 2’s complement can be formed by leaving all least significant 0’s and
the first 1 unchanged an replacing 1’s with 0’s and 0’s with 1’s in all other higher
significant digits.

- FHE
2’s Complement

▪ Largest Positive Number: 0 1111111 +(127)10


▪ Largest Negative Number: 1 0000000 -(128)10
▪ Zero: 0 0000000
▪ Range: -(128)10 to +(127)10
▪ The most significant bit still represents the sign:
0 = +ve; 1 = -ve.

- FHE
2’s Complement

▪ Examples (assuming 8-bit binary numbers):


(14)10 = (00001110)2 = (00001110)2s
-(14)10 = -(00001110)2 = (11110010)2s
-(80)10 = -( ? )2 = ( ? )2s

- FHE
COMPARISONS OF SIGN-AND-MAGNITUDE AND
COMPLEMENTS
▪ Example: 4-bit signed number (positive values)
Value Sign-and- 1s 2s
Magnitude Comp. Comp.
+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

- FHE
COMPARISONS OF SIGN-AND-MAGNITUDE AND
COMPLEMENTS
▪ Example: 4-bit signed number (negative values)
Value Sign-and- 1s 2s
Magnitude Comp. Comp.
-0 1000 1111 -
-1 1001 1110 1111
-2 1010 1101 1110
-3 1011 1100 1101
-4 1100 1011 1100
-5 1101 1010 1011
-6 1110 1001 1010
-7 1111 1000 1001
-8 - - 1000

- FHE
BINARY ARITHMETIC OPERATIONS
FOR UNSIGNED NUMBERS
▪ ADDITION
▪ Like decimal numbers, two numbers can be added by
adding each pair of digits together with carry propagation.

(11011)2 (647)10
+ (10011)2 + (537)10
(101110)2 (1184)10

* Remember, in binary, 0+0=0, 1+0 = 1, 1+1 = 10, 1+1+1 = 11. When the addition results
in a 2 digits number (i.e. 10, 11), the most significant bit (MSB) propagates (if applicable)
to the next stage.
- FHE
BINARY ARITHMETIC OPERATIONS
FOR UNSIGNED NUMBERS
▪ SUBTRACTION
▪ Two numbers can be subtracted by subtracting each pair
of digits together with borrowing, where needed.

(11001)2 (627)10
- (10011)2 - (537)10
(00110)2 (090)10

- FHE
PROBLEM IN SIGNED ARITHMETIC
OPERATION: OVERFLOW
▪ Signed binary numbers are of a fixed range.
▪ If the result of addition/subtraction goes beyond this range, overflow occurs.
▪ Two conditions under which overflow can occur are:
(i) positive add positive gives negative
(ii) negative add negative gives positive

- FHE
OVERFLOW
▪ Examples: 4-bit numbers (in 2’s complement)
▪ Range: (1000)2s to (0111)2s or (-810 to 710)
(i) (0101)2s + (0110)2s= (1011)2s
(5)10 + (6)10= -(5)10 ?! (overflow!)

(ii) (1001)2s + (1101)2s = (10110)2s discard end-carry


= (0110)2s
(-7)10 + (-3)10 = (6)10 ?! (overflow!)

- FHE
2’s Complement Addition/Subtraction

▪ Algorithm for addition, A + B:


1. Perform binary addition on the two numbers.
2. Ignore the carry out of the MSB (most significant bit).
3. Check for overflow: Overflow occurs if the ‘carry in’ and
‘carry out’ of the MSB are different, or if result is opposite sign
of A and B.
▪ Algorithm for subtraction, A – B:
A – B = A + (–B)
1. Take 2s complement of B by inverting all the bits and
adding 1.
2. Add the 2s complement of B to A.

- FHE
2’s Complement Addition/Subtraction

▪ Examples: 4-bit binary system


+3 0011 -2 1110
+ +4 + 0100 + -6 + 1010
---- ------- ---- -------
+7 0111 -8 11000
---- ------- ---- -------
+6 0110 +4 0100
+ -3 + 1101 + -7 + 1001
---- ------- ---- -------
+3 10011 -3 1101
---- ------- ---- -------

▪ Which of the above is/are overflow(s)?

- FHE
2’s Complement Addition/Subtraction

▪ More examples: 4-bit binary system


-3 1101 +5 0101
+ -6 + 1010 + +6 + 0110
---- ------- ---- -------
-9 10111 +11 1011
---- ------- ---- -------

▪ Which of the above is/are overflow(s)?

- FHE
1’s Complement Addition/Subtraction

▪ Algorithm for addition, A + B:


1. Perform binary addition on the two numbers.
2. If there is a carry out of the MSB, add 1 to the result.
3. Check for overflow: Overflow occurs if result is opposite sign of A and B.
▪ Algorithm for subtraction, A – B:
A – B = A + (–B)
1. Take 1s complement of B by inverting all the bits.
2. Add the 1s complement of B to A.

- FHE
1’s Complement Addition/Subtraction
▪ Examples: 4-bit binary system
+3 0011 +5 0101
+ +4 + 0100 + -5 + 1010
---- ------- ---- -------
+7 0111 -0 1111
---- ------- ---- -------

-2 1101 -3 1100
+ -5 + 1010 + -7 + 1000
---- ------ ---- -------
-7 10111 -10 10100
---- + 1 ---- + 1
------ -------
1000 0101

- FHE
BCD CODE
• Binary Coded Decimal (BCD) is a widely used way to present decimal
numbers in binary form.
• Combines features of both decimal and binary systems.
• Each digit is converted to a binary equivalent (requires 4 bits).
• BCD is also known as the 8421 code.
• Suitable for interfaces such as keypad inputs and digital readouts.
• BCD is not a number system.
• It is a decimal number with each digit encoded to its binary equivalent.
• A BCD number is not the same as a straight binary number.
• The primary advantage of BCD is the relative ease of converting to and from
decimal.

- FHE
BCD CODE
• Convert the number 87410 to BCD:
• Each decimal digit is represented using 4 bits.
• Each 4-bit group can never be greater than 9.
8 7 4 (Decimal)

1000 0111 0100 (BCD)

• Reverse the process to convert BCD to decimal.


1001 0100 0011 (BCD)

9 4 3 (Decimal)

- FHE
BCD CODE
• Convert 0110100000111001 (BCD) to its decimal equivalent.

Divide the BCD number into four-bit


groups and convert each to decimal.

- FHE
BCD CODE
• Convert BCD 011111000001 to its decimal equivalent.

The forbidden group represents


an error in the BCD number.

- FHE
BCD Addition
Consider the addition of (184+576) in BCD:

BCD:
1 1 Carry-out from Previous Stage
0001 1000 0100 184 (Decimal)
+0101 0111 0110 +576 (Decimal)
Binary Sum: 0111 10000 1010
Add 6: 0110 0110
___________________________________________
BCD Sum: 0111 0110 0000 760

* If the binary sum is greater than or equal to 1010, we add 0110 to the
binary sum to obtain the correct BCD sum and a carry.
- FHE
THE GRAY CODE
• The Gray code is used in applications where numbers change rapidly.
• Only one bit changes from each value to the next.

Three bit binary


and Gray code
equivalents.

- FHE
THE GRAY CODE

Binary to Gray Gray to Binary

- FHE
PUTTING IT ALL TOGETHER
Decimal numbers 1 – 15 in binary, hex, BCD, Gray

- FHE

You might also like