You are on page 1of 113

ECT 203 LOGIC CIRCUIT DESIGN

Module 1
Binary and Hexadecimal number systems; Methods of
base conversions; Binary and Hexadecimal arithmetic;
Representation of signed numbers; Fixed and floating
point numbers; Binary coded decimal codes; Gray
codes; Excess 3 code. Alphanumeric codes: ASCII
Analog quantity
• An analog quantity is one having continuous values.
• Most things that can be measured quantitatively
occur in nature in analog form.
• Example- room temperature, light intensity, sound

9/30/2022 ECT203 Module 1 2


9/30/2022 ECT203 Module 1 3
9/30/2022 ECT203 Module 1 4
9/30/2022 ECT203 Module 1 5
9/30/2022 ECT203 Module 1 6
Decimal Number System
• Ten Digits 0,1,2,3,4,5,6,7,8,9- To represent a
quantity
• Base-10 system
• Is “02” and “20” same?

9/30/2022 ECT203 Module 1 7


Decimal Number System
• Weights for whole numbers are positive powers of ten that
increase from right to left, beginning with 100=1.

• For Fractional numbers, weights are negative powers of 10


that decreases from left to right beginning with 10-1.

9/30/2022 ECT203 Module 1 8


Binary number System
• Another way to represent quantities
• Has only two digits- 0 and 1.
• Base-2 system
• Position of 1 or 0 in a binary number indicates
its weight or value within the number.

9/30/2022 ECT203 Module 1 9


Counting in Binary
0
1
10
11
100
101
110
111
1000
1001

9/30/2022 ECT203 Module 1 10


Note the patterns with which 1s and
0s alternate in each column

9/30/2022 A binary count of zeroECT203


through fifteen
Module 1 shown in Table. 11
Counting Range
• With n bits you can count up to a number
equal to 2n-1.
– Largest decimal number = 2n-1

9/30/2022 ECT203 Module 1 12


Weighting structure of Binary numbers

• Where n is the number of bits from the binary


point

9/30/2022 ECT203 Module 1 13


Binary-to-Decimal Conversion
• Add the weights of all 1s in a binary number
to get the decimal value.

9/30/2022 ECT203 Module 1 14


Problem

9/30/2022 ECT203 Module 1 15


Octal numbers

• Base-8 system

9/30/2022 ECT203 Module 1 16


Octal-to-Decimal Conversion

9/30/2022 ECT203 Module 1 17


Hexadecimal Number System
• Has sixteen characters
• Used as a compact way of displaying or
writing binary numbers.
• Base-16
• Consists of digits 0-9 and letters A, B, C, D, E, F.

9/30/2022 ECT203 Module 1 18


9/30/2022 ECT203 Module 1 19
Counting in Hexadecimal

9/30/2022 ECT203 Module 1 20


Decimal-to-octal conversion

9/30/2022 ECT203 Module 1 21


Octal-to-binary conversion

9/30/2022 ECT203 Module 1 22


Binary-to-Octal Conversion

9/30/2022 ECT203 Module 1 23


9/30/2022 ECT203 Module 1 24
Decimal-to-Binary Conversion
Sum-of-weights method
• Determine the set of binary weights whose
sum is equal to decimal number.
• A list of seven binary weights would be 64, 32,
16, 8, 4, 2, 1.
• For e.g. Decimal number 9 can be expressed
as the sum of binary weights as follows
9= 8+1=23+20 1001

9/30/2022 ECT203 Module 1 25


Problem

9/30/2022 ECT203 Module 1 26


Repeated division-by-2 method
• Divide the decimal number by 2 until the
quotient is 0. Remainders form the binary
number.
• First remainder produced is the LSB(Least
significant bit) in the binary number.
• Last remainder produced is the MSB(Most
significant bit) in the binary number.

9/30/2022 ECT203 Module 1 27


Problem: To convert decimal number
12 to binary.

9/30/2022 ECT203 Module 1 28


9/30/2022 ECT203 Module 1 29
Converting Decimal fractions to Binary
• An easy way to remember fractional binary
weights is that the most significant weight is
0.5, and that halving any weight, you get next
lower weight.
• List of four fractional binary weights would be
0.5, 0.25, 0.125, 0.0625

9/30/2022 ECT203 Module 1 30


9/30/2022 ECT203 Module 1 31
Repeated multiplication by 2
• Convert the decimal fraction 0.3125 to binary

9/30/2022 ECT203 Module 1 32


Practice Problem

9/30/2022 ECT203 Module 1 33


Binary-to-Hexadecimal Conversion
• Break the binary number into 4-bit groups, starting at the
right-most bit and replace each 4-bit group with the
equivalent hexadecimal symbol

9/30/2022 ECT203 Module 1 34


Hexadecimal-to-binary Conversion
• Replace each hexadecimal symbol with the
appropriate four bits

9/30/2022 ECT203 Module 1 35


Hexadecimal-to-Decimal Conversion-
Method 1
• First convert Hexadecimal number to Binary
and then convert from Binary to decimal.

9/30/2022 ECT203 Module 1 36


Hexadecimal-to-Decimal Conversion-
Method 2
• Multiply the decimal value of each
hexadecimal digit by its weight and then take
sum of these products.

9/30/2022 ECT203 Module 1 37


Example

9/30/2022 ECT203 Module 1 38


Decimal-to-Hexadecimal Conversion
• Repeated division of decimal number by 16 will produce
the equivalent hexadecimal number, formed by the
remainders of the division.
• First remainder produced is Least Significant Digit(LSD)
• Each successive division by 16 yields a remainder that
becomes a digit in the equivalent hexadecimal number.
• Note: when a quotient has a fractional part, the
fractional part is multiplied by the divisor to get the
remainder.

9/30/2022 ECT203 Module 1 39


Example

9/30/2022 ECT203 Module 1 40


Binary Arithmetic
• Binary Addition

9/30/2022 ECT203 Module 1 41


• When binary numbers are added, the last condition creates a
sum of 0 in given column and a carry of 1 over to the next
column to the left.
• Add 11+1

9/30/2022 ECT203 Module 1 42


• When 3 bits are being added( a bit in each of
the two numbers and a carry bit)

9/30/2022 ECT203 Module 1 43


9/30/2022 ECT203 Module 1 44
Binary Subtraction

9/30/2022 ECT203 Module 1 45


9/30/2022 ECT203 Module 1 46
Binary Multiplication

9/30/2022 ECT203 Module 1 47


Binary Division

9/30/2022 ECT203 Module 1 48


Practice Problem

9/30/2022 ECT203 Module 1 49


Complements of Binary numbers
• 1’s complement and 2’s complement of a binary
number are important because they permit the
representation of negative numbers.

9/30/2022 ECT203 Module 1 50


9/30/2022 ECT203 Module 1 51
9/30/2022 ECT203 Module 1 52
Signed Numbers
• Digital systems, such as computer, must be able to handle both positive
and negative numbers.
• A signed binary number consists of both sign and magnitude information.
• The sign indicates whether the number is positive or negative and
magnitude is the value of the number.
• Number of ways a signed integer (whole) numbers can be
represented in binary
– Sign magnitude –Least used
– 1’s complement
– 2’s complement
• Non integer and very large or small numbers can be
expressed in floating-point format.

9/30/2022 ECT203 Module 1 53


• sign bit
–Leftmost bit in a signed binary
number
–A 0 sign bit indicates a positive
number, and a 1 sign bit indicates a
negative number

9/30/2022 ECT203 Module 1 54


Sign-Magnitude form
• The left-most bit is the sign bit and the remaining
bits are the magnitude bits.
• The magnitude bits are in true (uncomplemented)
binary for both positive and negative numbers.
– For e.g. Decimal number +25 is expressed as an 8-bit
binary number in sign magnitude form is
00011001
 Decimal number -25 is expressed as
10011001

9/30/2022 ECT203 Module 1 55


1’s compliment form
• +25 00011001

• -25 11100110
In the 1’s compliment form, a negative
number is the 1’s complement of the
corresponding positive number.

9/30/2022 ECT203 Module 1 56


2’s Complement form

• +25 00011001

• -25 11100111

In the 2’s compliment form, a negative


number is the 2’s complement of the
corresponding positive number.
9/30/2022 ECT203 Module 1 57
9/30/2022 ECT203 Module 1 58
Decimal value of signed numbers
• Sign-magnitude

9/30/2022 ECT203 Module 1 59


9/30/2022 ECT203 Module 1 60
1’s Compliment
• Decimal values of positive numbers in the 1’s
complement form are determined by summing
the weights in all bit positions where there are 1s
and ignoring those positions where are zeroes.
• Decimal values of negative numbers are
determined by assigning a negative value to the
weight of the sign bit, summing all the weights
where there are 1s, and adding 1 to the result.

9/30/2022 ECT203 Module 1 61


9/30/2022 ECT203 Module 1 62
2’s Compliment
• Decimal values of positive and negative
numbers are determined by summing the
weights in all bit positions where there are 1s
and ignoring those positions where there are
zeroes.
• The weight of the sign bit in a negative
number is given a negative value.

9/30/2022 ECT203 Module 1 63


9/30/2022 ECT203 Module 1 64
Range of signed Integer numbers
• For 2’s complement signed numbers, the range of
values for n-bit numbers is
Range = -(2n-1) to +(2n-1-1)
Where in each case there is one sign bit and n-1
magnitude bits.
 For n=4, Range -(23) = -8 to 23 -1 =+7
 For n=8, Range -128 to +127
 For n=16, Range -32,768 to 32,767
• There is one less positive number than there are
negative numbers because zero is represented as a
positive number (all zeros).

9/30/2022 ECT203 Module 1 65


Decimal Signed 2’s
compliment

+3 011
+2 010
+1 001
+0 000
-0 000
-1 111
-2 110
-3 101
-4 100
9/30/2022 ECT203 Module 1 66
Signed(2’s complement) Arithmetic

9/30/2022 ECT203 Module 1 67


9/30/2022 ECT203 Module 1 68
9/30/2022 ECT203 Module 1 69
9/30/2022 ECT203 Module 1 70
Addition of a string of numbers

9/30/2022 ECT203 Module 1 71


Subtraction
• Subtraction is the special case of addition.
• For example, subtracting +6 (the subtrahend)
from +9 (the minuend) is equivalent to adding
-6 to +9.
• Subtraction process changes the sign of the
subtrahend and adds to the minuend.
• The sign of a positive or negative binary
number is changed by taking its 2’s
complement.
9/30/2022 ECT203 Module 1 72
• For example
• 00000011 +3
• 2’s compliment of 00000011 is 11111101 which is
-128+64+32+16+8+4+1= -3 ;
• Another example 11111100 is -4
• 2’s compliment of 11111100 is 00000100 =+4
• To subtract two signed numbers, take the 2’s
complement of the subtrahend and add. Discard
any final carry bit.

9/30/2022 ECT203 Module 1 73


9/30/2022 ECT203 Module 1 74
9/30/2022 ECT203 Module 1 75
Hexadecimal Arithmetic
Hexadecimal Addition
The rules for adding two Hexadecimal digits

9/30/2022 ECT203 Module 1 76


9/30/2022 ECT203 Module 1 77
Hexadecimal subtraction
• The 2’s complement method allows to
subtract by adding binary numbers.
• Three ways to get the 2’s compliment of a
hexadecimal number.

9/30/2022 ECT203 Module 1 78


9/30/2022 ECT203 Module 1 79
9/30/2022 ECT203 Module 1 80
9/30/2022 ECT203 Module 1 81
9/30/2022 ECT203 Module 1 82
Fixed and Floating-point numbers
• To represent rational numbers
• Fixed-point numbers are analogous to
decimals ; some of the bits represent the
integer part, rest represent fraction
• Floating-point numbers are analogous to
scientific notation, with a mantissa and an
exponent.
A rational number is a number that can be in the form p/q
where p and q are integers and q is not equal to zero.
9/30/2022 ECT203 Module 1 83
Fixed-point number system
• Has an implied binary point between the
integer and fraction bits.
Fixed-point number with four integer bits and four
fraction bits. Example 01101100
Shows the implied binary point 0110.1100
Equivalent decimal value is
22+21+2-1+2-2

9/30/2022 ECT203 Module 1 84


• Signed fixed-point numbers can use either two’s
complement or sign-magnitude notation
– Example fixed-point representation of -2.375 is
– Sign and magnitude form 1010.0110
– 2’s complement form 1101.1010
(inverting the bits of the absolute value and adding 1 to the
least significant(rightmost) bit.)
• Fixed-point numbers are just a collection of bits.
There is no way of knowing the existence of the
binary point except through agreement of those
people interpreting the number.
9/30/2022 ECT203 Module 1 85
Problem
• Express the following base-10 numbers in 16-bit
fixed-point sign-magnitude format and 2’s
complement format with eight integer bits and eight
fraction bits.
a) -13.5625
b) 42.3125
c) -17.15625

9/30/2022 ECT203 Module 1 86


Floating-point number system
• Allows the representation of very large and
very small numbers
• Scientific notation ±MxBE :sign , mantissa(M),
base (B) and exponent (E)
• Example; 3.1x103 is the decimal scientific
notation for 3100. It has mantissa of 3.1, a
base of 10 and an exponent of 3.

9/30/2022 ECT203 Module 1 87


• Floating-point numbers are base-2 with a binary
mantissa. 32 bits are used to represent 1 sign bit, 8
exponent bits, and 23 mantissa bits.
• Q-Write the floating-point representation of
the decimal number 228.
• 22810=111001002 =1.110012x 27.
1 bit 8 bits 23 bits
0 00000111 111 0010 0000 0000 0000 0000
Sign Exponent Mantissa
32-bit floating-point version 1

9/30/2022 ECT203 Module 1 88


• In binary floating-point, the first bit of the
mantissa(to the left of the binary point) is
always 1 and therefore need not be stored.
1 bit 8 bits 23 bits
0 00000111 110 0100 0000 0000 0000 0000
Sign Exponent Fraction

32-bit floating-point version 2

9/30/2022 ECT203 Module 1 89


One final modification to the Exponent
field
• The exponent needs to represent both positive and negative
exponents. The floating point numbers use a biased exponent,
which is original exponent plus a constant bias.
• For example- For the exponent 7, the biased exponent is
7+127=134=100001102.
 For the exponent -4, the biased exponent is -4+127=123=011110112.
1 bit 8 bits 23 bits
0 10000110 110 0100 0000 0000 0000 0000

Sign Biased Fraction


exponent
IEEE 754 floating-point notation(Single-precision format)

9/30/2022 ECT203 Module 1 90


Problem
• Express the following base-10 numbers in 16-
bit floating-point sign-magnitude format and
2’s complement format with eight integer bits
and eight fraction bits.
a) -13.5625
b) 42.3125
c) -17.15625

9/30/2022 ECT203 Module 1 91


Binary Coded Decimal(BCD)
• A way to express each of the decimal digits
with a binary code.
• Only ten code groups in the BCD system
The 8421 BCD code
 A type of BCD code
Each decimal digit is represented by a 4-bit binary
code.
8421 indicates the binary weights of four bits(23,
22, 21, 20)

9/30/2022 ECT203 Module 1 92


Binary combinations that represent
decimal digits

9/30/2022 ECT203 Module 1 93


Invalid codes
Six code combinations----1010,1011, 1100,
1101, 1110, 1111---are invalid in 8421 BCD
code.
To express any decimal number in BCD, simply
replace each decimal digit with the
appropriate 4-bit code.

9/30/2022 ECT203 Module 1 94


9/30/2022 ECT203 Module 1 95
Start at the right-most bit and break the code into groups of four bits

9/30/2022 ECT203 Module 1 96


Applications of BCD code- To display
decimal numbers
• Digital clocks
• Digital thermometers
• Digital meters
• Devices with seven segment display
• Note- BCD is not efficient as straight binary for
calculations, but is useful if only limited
processing is required.

9/30/2022 ECT203 Module 1 97


BCD

A lab experiment in which BCD is


converted to decimal is shown.

9/30/2022 ECT203 Module 1 98


BCD Addition
• Step 1- Add the two BCD numbers
• Step 2- If a 4-bit sum is equal to or less than 9, it
is a valid BCD number.
• Step 3- if a 4-bit sum is greater than 9, or if a
carry out of the 4-bit group is generated, it is an
invalid result. Add 6(0110) to the 4-bit sum in
order to skip the six invalid states and return the
code to 8421. If a carry results when 6 is added,
simply add the carry to the next 4-bit group.
9/30/2022 ECT203 Module 1 99
9/30/2022 ECT203 Module 1 100
9/30/2022 ECT203 Module 1 101
9/30/2022 ECT203 Module 1 102
Digital codes
• Many specialized codes are used in digital systems.
• Example—BCD code, Gray code, ASCII code
• Some codes are strictly numeric while others are
alphanumeric; used to represent numbers, letters,
symbols and instructions.

9/30/2022 ECT203 Module 1 103


The Gray code
• Unweighted code
• It exhibits only a single-bit change from one code word to the
next in sequence.

9/30/2022 ECT203 Module 1 104


Binary-to-Gray code conversion
• Rules:

9/30/2022 ECT203 Module 1 105


Gray-to-Binary code conversion

9/30/2022 ECT203 Module 1 106


9/30/2022 ECT203 Module 1 107
Gray code Decimal Binary Gray code
0 0000 0000
1 0001 0001
Gray code is used to avoid 2 0010 0011
problems in systems where an 3 0011 0010
error can occur if more than one 4 0100 0110
5 0101 0111
bit changes at a time. 6 0110 0101
7 0111 0100
8 1000 1100
9 1001 1101
10 1010 1111
11 1011 1110
12 1100 1010
13 1101 1011
14 1110 1001
15 1111 1000

9/30/2022 ECT203 Module 1 108


Gray code
• A shaft encoder is a typical application. Three IR
emitter/detectors are used to encode the position of
the shaft. The encoder on the left uses binary and
can have three bits change together, creating a
potential error. The encoder on the right uses gray
code and only 1-bit changes, eliminating potential
errors.

9/30/2022 ECT203 Module 1 109


An application->3-bit shaft position encoder
Three IR emitter/detectors are used to encode the position of the shaft. The
encoder on the left uses binary and can have three bits change together, creating
a potential error. The encoder on the right uses gray code and only 1-bit changes,
eliminating potential errors.

9/30/2022 ECT203 Module 1 110


Excess-3 code
• Unweighted code .Each coded combination is obtained from
the corresponding binary value plus 3.
Decimal Digit BCD 8421 Excess-3
0 0000 0011
1 0001 0100
2 0010 0101
3 0011 0110
4 0100 0111
5 0101 1000
6 0110 1001
7 0111 1010
8 1000 1011
9 1001 1100

9/30/2022 ECT203 Module 1 111


ASCII code-American Standard Code
for Information Interchange
• ASCII is a code for alphanumeric characters and control
characters.
• Most computer keyboards use ASCII
• When you enter a letter, a number, or control
command, the corresponding ASCII code goes into the
computer.
• In its original form, ASCII encoded 128 characters and
symbols using 7-bits.
• The first 32 characters are control characters, that are
based on obsolete teletype requirements, so these
characters are generally assigned to other functions in
modern usage.

9/30/2022 ECT203 Module 1 112


• Actually, ASCII can be considered an 8-bit code
with the MSB always 0. This 8-bit code is 00
through 7F in hexadecimal.
• In 1981, IBM introduced extended ASCII, which is
an 8-bit code and increased the character set to
256.
• Other extended sets (such as Unicode) have
been introduced to handle characters in
languages other than English.
• ***********************
9/30/2022 ECT203 Module 1 113

You might also like