Download as pdf or txt
Download as pdf or txt
You are on page 1of 172

Digital Electronics: CT 304N

Unit:1
Number Systems and Codes

Dr. Anand J. Patel


Teaching scheme
• 4 lectures + 2 hours laboratory = 6 hours weekly
• Total 5 credits
• Evaluation Scheme:
• 70 (external) +30 (mid-sem exam) +20 (CIA) +30 (Practical)
• Total = 150 marks
Reference Books:
• 1. M. Morris Mano- Digital logic and computer Design, PHI
• 2. G.K.Kharate-Digital Electronics, Oxford
• 3. A. Anand Kumar- Fundamentals of Digital Circuits, PHI
• 4. R.P.Jain- Digital Electronics, TMH
• 5. B. Somanathan Nair- Digital Electronics and Logic Design, PHI
Unit 1: Index
• Decimal, Binary, octal, and hexa-decimal number systems
• Binary arithmetic
• Number base conversions
• Complements
• Codes: Binary code, excess-3 code, gray code, error detection and
correction codes
Common Number Systems

Used by Used in
System Base Symbols humans computers
? ?
Decimal 10 0, 1, … 9 Yes No
Binary 2 0, 1 No Yes
Octal 8 0, 1, … 7 No No
Hexa- 16 0, 1, … 9, No No
decimal A, B, … F
The Decimal Number System

• The decimal system is the base-10 system that we use


every day.
• A number, say 6357, represented in the base-10
system consists of multiple ordered digits. (In other
words, digits are normally combined together in
groups to create larger numbers.)
• A digit is a single place that can hold numerical values
between 0 and 9 (10 different values).
Let us start from an arbitrary decimal
number
• For example, 6,357 has four digits.

• It is understood that in the number 6,357,


• the 7 is filling the "1s place,"
• while the 5 is filling the 10s place,
• the 3 is filling the 100s place
• and the 6 is filling the 1,000s place. 10^3

• So you could express 6,357 this way if you want to be


explicit:
(6 * 1000) + (3 * 100) + (5 * 10) + (7 * 1)
= 6000 + 300 + 50 + 7
= 6357
Continue ..

• Another way to express it would be to use the


concept of powers of 10.
• A specific digit is associated with a specific weight
expressed as powers of 10. The first digit (counting
from the right) gives 10 to the 0 power, the second
digit gives 10 to the 1 power, and so on.
• Exponents are a shorthand way to show how many times a number,
called the base, is multiplied times itself. A number with an exponent
is said to be "raised to the power" of that exponent.
• Assuming that we are going to represent the concept of "raised to the
power of" with the "^" symbol.
• "10 squared“ or 10 to the power of 2 is written as "10^2"
• 10 to the fourth power is denoted 10^4
• Thus, another way to express the previous number is like this:
(6 * 10^3) + (3 * 10^2) + (5 * 10^1) + (7 * 10^0)
= 6000 + 300 + 50 + 7
= 6357
• What you can see from this expression is that each
digit is a placeholder for the power of the index of
that placeholder of base 10, starting from the least
significant digit with 10 raised to the power of zero
(i.e. counting from the rightmost digit).
• But why do we human beings use 10 based number system?
• The most commonly accepted explanation is that our base-10
number system was adopted by our ancestors most likely because we
have 10 fingers.
• Interestingly enough, maybe that is why digit in English also means a
finger or toe.
• We have reasons to ask a question in our minds:
• “If we happened to evolve to have eight fingers instead, would we probably
have a base-8 number system?”
• The answer is probably YES!
Any other number systems?
• The good news about number systems is that it is not
the only choice to have 10 different values in a digit.
• Actually, we can have base-anything number systems
from a theoretical point of view.
• There are many good reasons to use different bases in
different situations. For example, 7 days/week, 12
months/year
A generalized rule
• The following rules apply to base 10 and to any other base number
system:
• The system of base n requires n different symbols or values.
• The left most digit is the highest-order digit and represents the most
significant digit, while the lowest-order digit is the least significant digit.
• A digit is represented as powers of the system's base.
• In any number system there are character to show number.
• There is a definite weightage to each position of number. This
weightage depends upon the base or radix. If radix is shown by R,
then any number can be represented as follow:
n n-1 4 3 2 1 0 -1
( )R + ( )R +.... ( )R +( )R +( )R +( )R +( )R . ( )R +
-2 -(m+1) m
( )R +....()R +()R

• where point separates the whole part and the fractional part.
• By following the general rule any number system can be developed.
Common Number Systems

Used by Used in
System Base Symbols humans computers
? ?
Decimal 10 0, 1, … 9 Yes No
Binary 2 0, 1 No Yes
Octal 8 0, 1, … 7 No No
Hexa- 16 0, 1, … 9, No No
decimal A, B, … F
Digital Electronics??
• Importance of the subject
• Motivation for studying the subject
Digital Era
• Digital age and information age
• Digital computers
• General purposes
• Many scientific, industrial and commercial applications
• Digital systems
• Telephone switching exchanges
• Digital camera
• Electronic calculators, PDA's
• Digital TV
• Discrete information-processing systems
• Manipulate discrete elements of information
• For example, {1, 2, 3, …} and {A, B, C, …}…
Analog and Digital Signal
• Analog system
• The physical quantities or signals may vary continuously over a specified
range.
• Digital system
• The physical quantities or signals can assume only discrete values.
• Greater accuracy

X(t) X(t)

t t
Analog signal Digital signal
Binary Digital Signal
• An information variable represented by physical quantity.
• For digital systems, the variable takes on discrete values.
• Two level, or binary values are the most prevalent values.
• Binary values are represented abstractly by:
V(t)
• Digits 0 and 1
• Words (symbols) False (F) and True (T)
• Words (symbols) Low (L) and High (H) Logic 1
• And words On and Off
undefine
• Binary values are represented by values
or ranges of values of physical quantities. Logic 0
t
Binary digital signal
Digital Systems and Binary Numbers
• Computers happen to operate using the base-2 number system, also
known as the binary number system, just like the base-10 number
system is known as the decimal number system to human beings.
The fundamental point
• Modern computers use binary number system, in which there are
only zeros and ones. (Only two symbols)
• A “bit” to binary is similar a “digit” to a decimal information. (Again,
the easiest way to understand bits is to compare them to something
you know: digits.)
• A bit has a single binary value, either 0 or 1.
Binary vs. Decimal
• Binary is a base two system which works just like our decimal system.
• Considering the decimal number system, it has a set of values which
range from 0 to 9.
• The binary number system is base 2 and therefore requires only two
digits, 0 and 1.
The fundamental point
• Binary representation of numbers and other information is the
representation which can be understood by computer chips and can
be saved in memory.
• It is important to computers because all computer data is ultimately
represented by a series of zeros and ones, no matter you realize it or
not.
You might ask
• Why don’t computers use the base-10 decimal system for numbers,
counting and arithmetic?
• Why not 4 based, 7 based?
• Why 2 based?
• We know that the computer doesn't have a real brain inside. In fact, it
is made up mostly of semiconductor materials such as silicon. Yet, a
computer acts in many ways as if it does have a real brain, because it
can store (memorize) data and derive new information (operations)
from the input data.
Why binary?

• These questions can be answered by a series of relevant questions!


• How to store the values in hardware?
• How to automatically perform arithmetic operations on numbers?
•…
• The fundamental question is can we find out a physical material to
stably maintain n different status?
How to store?
• Advancement in material science guarantees that binary status can be
represented with no ambiguity.
• Silicon and many other semiconductor materials can present one of
two status at any given time, and can retain a status for a long time.
• Positive or negative, +5 volt or -5 volt.
• Think about 2 status in electronic world, if not One then Zero, very
simple to implement in electronic world.
• One the other hand, it is difficult, if not impossible, to find out a
material to be able to maintain 10 different status stably.
• Generally speaking, the more status to maintain, the more difficult to
find out such a material.
How to calculate
• Another factor is how to implement proper digital circuits to perform
arithmetic and logical operations based on a specific number system.
• It turns out that the binary system is the preferred way to implement
CPUs to do various operations (arithmetic and logical operations).
• Not any other systems!
• You could wire up and build computers that operate in base-10
(assume physically we can find out such kind of material.), but they
would be fiendishly expensive right now.
• On the other hand, base-2 computers are relatively cheap.
• Also because there must always be at least two symbols for an
information processing system to be able to distinguish significances
of different values and to manipulate on them, binary is the smallest
numbering system that supports definite arithmetic and logic
operations.
The simplest answer is
• Basically speaking, binary system simplifies information
representation and information processing in electronic world.
• Binary number system is the easiest one to implement from the
hardware point of view.
• The binary number system suits a computer extremely well, because
it allows simple CPU and memory designs.
• It is very difficult to design circuits that require ten distinct states.
• So computers use binary numbers.
• Their CPU and memory are made up of millions of tiny “switches”
that can be either ON or OFF. Two symbols, 0 and 1, can be used to
stand for the two states of ON and OFF.
• Since the computer is really made up of tiny switches that can be
either OFF or ON, you can look at a binary number as a series of light
switches. A 1 represents a switch that is ON, and a 0 means a switch
that is OFF.
• The computer's CPU needs only recognize two states, in the same way
as a switch must always be open or closed, or an electrical flow on or
off, a binary digit must always be one or zero.
• on or off,
• Yes or no,
• 1 or 0.

• But from this on-off, yes-no 1-0 state, all things may can be
represented completely and calculated correctly.
Digital Systems and Binary Numbers
• As digital systems are more efficient than analog systems they are
more prevalent today i.e. digital computers, digital cameras etc.
• Binary logic is the simplest to implement in a digital system.
• So, digital systems with binary logic are used.

Logic 1

undefine

Logic 0
Decimal Number System
• Base (also called radix) = 10
• 10 digits { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
• Digit Position 2 1 0 -1 -2

• Integer & fraction 5 1 2 7 4


• Digit Weight
100 10 1 0.1 0.01
• Weight = (Base) Position
• Magnitude
• Sum of “Digit x Weight”
500 10 2 0.7 0.04
• Formal Notation
d2*B2+d1*B1+d0*B0+d-1*B-1+d-2*B-2

(512.74)10
Octal Number System
• Base = 8
• 8 digits { 0, 1, 2, 3, 4, 5, 6, 7 }
64 8 1 1/8 1/64
• Weights
5 1 2 7 4
• Weight = (Base) Position
2 1 0 -1 -2
• Magnitude
5 *82+1 *81+2 *80+7 *8-1+4 *8-2
• Sum of “Digit x Weight”
• Formal Notation =(330.9375)10

(512.74)8
Binary Number System
• Base = 2
• 2 digits { 0, 1 }, called binary digits or “bits”
• Weights
4 2 1 1/2 1/4
• Weight = (Base) Position
1 0 1 0 1
• Magnitude
• Sum of “Bit x Weight” 2 1 0 -1 -2
1 *22+0 *21+1 *20+0 *2-1+1 *2-2
• Formal Notation
• Groups of bits 4 bits = Nibble
=(5.25)10

8 bits = Byte (101.01)2


1011

11000101
Hexadecimal Number System
• Base = 16
• 16 digits { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F }
• Weights
Position 256 16 1 1/16 1/256
• Weight = (Base)
1 E 5 7 A
• Magnitude
• Sum of “Digit x Weight” 2 1 0 -1 -2
1 *162+14 *161+5 *160+7 *16-1+10 *16-2
• Formal Notation
=(485.4765625)10

(1E5.7A)16
Common Number Systems

Used by Used in
System Base Symbols humans computers
? ?
Decimal 10 0, 1, … 9 Yes No
Binary 2 0, 1 No Yes
Octal 8 0, 1, … 7 No No
Hexa- 16 0, 1, … 9, No No
decimal A, B, … F
Conversion Among Bases
• The possibilities:

Decimal Octal

Binary Hexadecimal
Conversions:
1. Decimal to Binary 7. Binary to octal
2. Binary to decimal 8. Binary to hexadecimal
3. Decimal to octal 9. Octal to hexadecimal
4. Octal to decimal 10. Octal to binary
5. Decimal to hexadecimal 11. Hexadecimal to octal
6. Hexadecimal to decimal 12. Hexadecimal to binary
1. Decimal to Binary Conversion

Decimal Octal

Binary Hexadecimal
Decimal to Binary Conversion

• Technique for integer part


• Divide by two, keep track of the remainder

• Technique for decimal fraction part


• Multiply by two, keep track of the remainder
Example 2 125
12510 = ?2 2 62 1

2 31 0
15 1
2
7 1
2
2 3 1

2 1 1
0 1

12510 = 11111012
Convert decimal fraction 0.78125 to binary
0.78125*2 = 1.5625 carry 1
0.5625 *2 = 1.125 carry 1
0.125 *2 = 0.25 carry 0
0.25 *2 = 0.5 carry 0
0.5 *2 = 1.0 carry 1

reading from top to bottom & writing left to right after


decimal point, we get (0.11001)2
Convert 0.6 into binary
0.6*2 = 1.2 carry 1
0.2*2 = 0.4 carry 0
0.4*2 = 0.8 carry 0
0.8*2 = 1.6 carry 1
0.6*2 = 1.2 carry 1

It is seen that there is no end to this example, so we


should stop somewhere depending upon the accuracy
desired.

(0.6)10 = (0.10011........)2
Practice: 1
• Find the binary equivalent of decimal 35

• Solve and give answer?


• (35)10 = ( ? )2 2 35

• Solution: 2 17 1 ↑
2 8 1 ↑
(35)10 = (_______)2 2 4 0 ↑
2 2 0 ↑
2 1 0 ↑
0 1 ↑

• ∴ (35)10 = (100011)2
Practice: 2
• Find the binary equivalent of decimal 0.35

• Solve and give answer?


• (0.35)10 = ( ? )2
0.35 × 2 = 0.70  0 ↓
• Solution: 0.70 × 2 = 1.40  1 ↓
(0.35)10 = (_______)2 0.40 × 2 = 0.80  0 ↓
0.80 × 2 = 1.60  1 ↓
0.60 × 2 = 1.20  1 ↓
0.20 × 2 = 0.40  0 ↓

• ∴ (0.35)10 = (0.010110)2
Combining 1 and 2
• Find the binary equivalent of decimal 35.35 is
• 100011.010110
2 35 0.35 × 2 = 0.70  0 ↓
2 17 1 ↑ 0.70 × 2 = 1.40  1 ↓
2 8 1 ↑ 0.40 × 2 = 0.80  0 ↓
2 4 0 ↑ 0.80 × 2 = 1.60  1 ↓
2 0 ↑
2
0.60 × 2 = 1.20  1 ↓
2 1 0 ↑
0.20 × 2 = 0.40  0 ↓
0 1 ↑
More examples:
• Find binary equivalent of following decimal numbers:
(i) 29
(ii) 47
(iii) 0.692
(iv) 0.8125
(v) 25.188
Answers:
• Find binary equivalent of:
(i) 29 = 11101
(ii) 47 = 101111
(iii) 0.692 = 0.1011
(iv) 0.8125 = 0.1101
(v) 25.188 = 11001.00110
Answers:

2 29
(29)10 = ( ? )2
2 14 1 ↑

Solution: 2 7 0 ↑
(29)10 = (_______)2
2 3 1 ↑

∴ (29)10 = (11101)2 2 1 1 ↑

0 1 ↑
Answers:

(47)10 = ( ? )2 2 47

2 23 1 ↑
Solution: 2 11 1 ↑
(47)10 = (_______)2
2 5 1 ↑

2 2 1 ↑
∴ (47)10 = (101111)2 2 1 0 ↑

0 1 ↑
Answer:
• (0.692)10 = ( ? )2
• Solution: (0.692)10 = (_______)2
• (0.692)10 = (0.101100)2
0.692 × 2 = 1.384  1 ↓
0.384 × 2 = 0.768  0 ↓
0.768 × 2 = 1.536  1 ↓
0.536 × 2 = 1.72  1 ↓
0.72 × 2 = 0.144  0 ↓
0.144 × 2 = 0.288  0 ↓
Answer:
• (0.8125)10 = ( ? )2
• Solution: (0.8125)10 = (_______)2
• (0.8125)10 = (0.1101)2

0.8125 × 2 = 1.6250  1 ↓
0.6250 × 2 = 1.2500  1 ↓
0.2500 × 2 = 0.5000  0 ↓
0.5000 × 2 = 1.0 1↓
• (25.188)10 = ( ? )2
• Solution: (25.188)10 = (_______)2
• ∴ (25.188)10 = (11001.001100)2

2 25 0.188 × 2 = 0.376  0 ↓
2 12 1 ↑ 0.376 × 2 = 0.752  0 ↓
2 6 0 ↑ 0.752 × 2 = 1.504  1 ↓
2 3 0 ↑ 0.504 × 2 = 1.8  1 ↓
2 1 1 ↑ 0.8 × 2 = 0.16  0 ↓
0 1 ↑ 0.16 × 2 = 0.32  0 ↓
2. Binary to Decimal Conversion

Decimal Octal

Binary Hexadecimal
Binary to Decimal Conversion

• Technique

• Multiply each bit by 2n, where n is the “weight” of the bit


• The weight is the position of the bit, starting from 0 on the
right
• Add the results
Example

Bit “0”

1010112 => 1 x 20 = 1
1 x 21 = 2
0 x 22 = 0
1 x 23 = 8
0 x 24 = 0
1 x 25 = 32
4310
If Binary number is 111.111, follow the given procedure as under.

=1x22 + 1x21 + 1x20 . 1x2-1 + 1x2-2 + 1x2-3

=1x4 + 1x2 + 1x1 . 1/2 + 1/4 + 1/8

=4 + 2 + 1 +. [(0.5) + (0.25) + (0.125)]

=7 + (0.875)

=7.875

(111.111)2 = (7.875)10
Practice: 1
• 1001012 = ( )10
Answer:
• (100101)2 = ( ? )10
• Solution: (100101)2 = (_______)10
100101
=1×25+0×24+0×23+1×22+0×21+1×20
=1×32 +0×16 +0×8 +1×4 +0×2 +1×1
=37
∴ (100101)2 = (37)10
Practice: 2
• 100011102 = ( )10
Answer:
• (10001110)2 = ( ? )10
• Solution: (10001110)2 = (_______)10
10001110
=1×27+0×26+0×25+0×24+1×23+1×22+1×21+0×20
=1×128 +0×64 +0×32 +0×16 +1×8 +1×4 +1×2 +0×1
=142
∴ (10001110)2 = (142)10
More examples:
• Find decimal equivalent of following binary numbers:
(i) 111101000 = ( )10
(ii) 10110101 = ( )10
(iii) 1010.1010 = ( )10
(iv) 1111.1111 = ( )10
(v) 1100.1100 = ( )10
Answers:
• Find binary equivalent of following decimal numbers:
(i) 1111010002 = 48810
(ii) 101101012 = 18110
(iii) 1010.1010 = 10.62510
(iv) 1111.1111 = 15.9410
(v) 1100.1100 = 12.7510
Answers:
• (111101000)2 = ( ? )10
• Solution: (111101000)2 = (_______)10
111101000
=1×28+1×27+1×26+1×25+0×24+1×23+0×22+0×21+0×20
=1×256 + 1×128 + 1×64 + 1×32 + 0×16 + 1×8 + 0×4 + 0×2 + 0×1
=488
∴ (111101000)2 = (488)10
Answers:
• (10110101)2 = ( ? )10
• Solution: (10110101)2 = (_______)10
10110101
=1×27+0×26+1×25+1×24+0×23+1×22+0×21+1×20
=1×128 + 0×64 + 1×32 + 1×16 + 0×8 + 1×4 + 0×2 + 1×1
=181
∴ (10110101)2 = (181)10
Answers:
• (1010.1010)2 = ( ? )10
• Solution:(1010.1010)2 = (_______)10
1010.1010
=1×23 +0×22 +1×21 +0×20 +1×2-1 +0×2-2 +1×2-3 +0×2-4
=1×8 + 0×4 + 1×2 + 0×1 + 1×0.5 + 0×0.25 + 1×0.125 + 0×0.0625
=10.625

∴ (1010.1010)2 = (10.625)10
Answers:
• (1111.1111)2 = ( ? )10
• Solution: (1111.1111)2 = (_______)10
1111.1111
=1×23+1×22+1×21+1×20+1×2-1+1×2-2+1×2-3+1×2-4
=1×8 + 1×4 + 1×2 + 1×1 + 1×0.5 + 1×0.25 +1×0.125 + 1×0.0625
=15.94
∴ (1111.1111)2 = (15.94)10
Answers:
• (1100.1100)2 = ( ? )10
• Solution: (1100.1100)2 = (_______)10
1100.1100
=1×23 +1×22 +0×21 +0×20 +1×2-1 +1×2-2 +0×2-3 +0×2-4
=1×8 +1×4 +0×2 +0×1 +1×0.5 +1×0.25 +0 +0
=12.75
∴ (1100.1100)2 = (12.75)10
3. Decimal to Octal Conversion

Decimal Octal

Binary Hexadecimal
Decimal to Octal Conversion

• Technique for integer part


• Divide by eight, keep track of the remainder
• Called ‘’octal dabble’’ method

• Technique for decimal fraction part


• Multiply by eight, keep track of the remainder
Example
123410 = ?8

8 1234
154 2
8
19 2
8
2 3
8
0 2

123410 = 23228
If decimal number is fraction, it is multiplied by 8 successively and
carry is written aside. The carry is read from top to bottom and is
written from left to right after the octal point.

(0.32)10 = (?)8

0.32*8 = 2.56 carry 2


0.56*8 = 4.48 carry 4
0.48*8 = 3.84 carry 3
0.84*8 = 6.72 carry 6

process continues further, so we can stop here.

(0.32) 10 = (0.2436)8
Practice: 1
• Find the octal equivalent of decimal 3542

• Solve and give answer?


• (3542)10 = ( ? )8 8 3542
• Solution: 8 442 6 ↑
(3542)10 = (_______)8 8 55 2 ↑
8 6 7 ↑
0 6 ↑

• ∴ (3542)10 = (6726)8
Practice: 2
• Find the binary equivalent of decimal 0.456

• Solve and give answer?


• (0.456)10 = ( ? )8
0.456 × 8 = 3.648  3 ↓
• Solution: 0.648 × 8 = 5.184  5 ↓
(0.456)10 = (_______)8 0.184 × 8 = 1.472  1 ↓
0.472 × 8 = 3.776  3 ↓
0.776 × 8 = 6.208  6 ↓
0.208 × 8 = 1.664  1 ↓

• ∴ (0.456)10 = (0.351361)8
More examples:
• Find octal equivalent of following decimal numbers:
(i) 2196
(ii) 4735
(iii) 0.69
(iv) 0.812
(v) 2562.86
Answers:
• Find octal equivalent of following decimal numbers:
(i) 2196 = (4224)8
(ii) 4735 = (11177)8
(iii) 0.69 = (0.541217)8
(iv) 0.812 = (0.637574)8
(v) 2562.86 = (5002.670243)8
• (2196)10 = ( ? )8 8 2196
• Solution: 8 274 4 ↑
(2196)10 = (_______)8 8 34 2 ↑
8 4 2 ↑
0 4 ↑

• ∴ (2196)10 = (4224)8
• (4735)10 = ( ? )8 8 4735

• Solution: 8 591 7 ↑
8 73 7 ↑
(4735)10 = (_______)8
8 9 1 ↑
8 1 1 ↑
0 1 ↑

• ∴ (4735)10 = (11177)8
• (0.812)10 = ( ? )8 0.812 × 8 = 6.496  6 ↓
0.496 × 8 = 3.968  3 ↓
• Solution: 0.968 × 8 = 7.744  7 ↓
(0.812)10 = (_______)8 0.744 × 8 = 5.952  5 ↓
0.952 × 8 = 7.616  7 ↓
0.616 × 8 = 4.928  4 ↓

• ∴ (0.812)10 = (0.637574)8
• (2562.86)10 = ( ? )8
• Solution:
(2562.86)10 = (_______)8

8 2562 0.86 × 8 = 6.88  6 ↓


8 320 2 ↑ 0.88 × 8 = 7.4  7 ↓
0.4 × 8 = 0.32  0 ↓
8 40 0 ↑
0.32 × 8 = 2.56  2 ↓
8 5 0 ↑
0.56 × 8 = 4.48  4 ↓
0 5 ↑ 0.48 × 8 = 3.84  3 ↓

• ∴ (2562.86)10 = (5002.670243)8
• (0.69)10 = ( ? )8 0.69 × 8 = 5.52  5 ↓
0.52 × 8 = 4.16  4 ↓
• Solution:
0.16 × 8 = 1.28  1 ↓
(0.69)10 = (_______)8 0.28 × 8 = 2.24  2 ↓
0.24 × 8 = 1.92  1 ↓
0.92 × 8 = 7.36  7 ↓

• ∴ (0.69)10 = (0.541217)8
4. Octal to Decimal Conversion

Decimal Octal

Binary Hexadecimal
Octal to Decimal Conversion

• Technique

• Multiply each bit by 8n, where n is the “weight” of the bit


• The weight is the position of the bit, starting from 0 on the right
• Add the results
Example

7248 => 4 x 80 = 4
2 x 81 = 16
7 x 82 = 448
46810
If Octal number is 0.536, follow the given procedure as
under.

=5x8-1 +3x8-2 + 6x8-3

=5x0.125 + 3x0.015625 + 6x0.001953125

=0.625 + 0.046875 + 0.01171875

=0.68359375

(0.536)8 = (0.68359375)10
5. Decimal to Hexadecimal

Decimal Octal

Binary Hexadecimal
Decimal to Hexadecimal Conversion

• Technique for integer part


• Divide by sixteen, keep track of the remainder

• Technique for decimal fraction part


• Multiply by sixteen, keep track of the remainder
Example
123410 = ?16

16 1234
16 77 2

16 4 13 = D
0 4

123410 = 4D216
If decimal number is fraction, it is multiplied by 16 successively and
carry is taken out. The carry is read from top to bottom and is written
from left to right after the hexadecimal point.

(0.35)10 = (?)16

0.35*16 = 5.6 carry 5


0.6 *16 = 9.6 carry 9
0.6 *16 = 9.6 carry 9
0.6 *16 = 9.6 carry 9

stopping here,

(0.35) 10 = (0.5999) 16
6. Hexadecimal to Decimal

Decimal Octal

Binary Hexadecimal
Hexadecimal to Decimal

• Technique

• Multiply each bit by 16n, where n is the “weight” of the bit


• The weight is the position of the bit, starting from 0 on the
right
• Add the results
Example

ABC16 => C x 160 = 12 x 1 = 12


B x 161 = 11 x 16 = 176
A x 162 = 10 x 256 = 2560
274810
If Hexadecimal number is E3.C7, follow the given procedure
as under.

=Ex161 + 3x160 . Cx16-1 + 7x16-2

=14x161 + 3x160 . 12x16-1 + 7x16-2

=224 + 3 . [0.75 + 0.02734375]

=227.[0.77734375]

=227. 77734375

(E3.C7)16 = (227. 77734375)10


7. Binary to Octal

Decimal Octal

Binary Hexadecimal
Binary to Octal

• Technique
• Group bits in threes, starting on right
• Convert to octal digits
Example:
10110101112 = ?8

001 011 010 111


Added zeros

1 3 2 7

10110101112 = 13278
(1101.1001)2 = (?)8
001 101 . 100 100

added 0 added 0

1 5 . 4 4

(1101.1001) 2= (15.44) 8
8. Binary to Hexadecimal

Decimal Octal

Binary Hexadecimal
Binary to Hexadecimal

• Technique
• Group bits in fours, starting on right
• Convert to hexadecimal digits
Example
10101110112 = ?16

10 1011 1011

2 B B

10101110112 = 2BB16
In case of a fraction number, groups are written on right hand side of
the binary digit.
For example,

(1111011101.1011101)2 = (?)16

0011 1101 1101 . 1011 1010


Added zeros
3 D D . B A

(1111011101.1011101)2 = (3DD.BA) 16
9. Octal to Binary Conversion

Decimal Octal

Binary Hexadecimal
Octal to Binary Conversion

• Technique
• Convert each octal digit to a 3-bit equivalent binary
representation
Example
7058 = ?2

7 0 5

111 000 101

7058 = 1110001012
If octal is a fraction number then also the same method is
adopted.
(0.326)8 = (?)2
3 2 6
011 010 110
(0.326) 8= (0.011 010 110) 2

(17.625) 8 = (?) 2
1 7 . 6 2 5
001 111 . 110 010 101
(17.625) 8 = (001 111.110 010 101) 2
10. Hexadecimal to Binary Conversion

Decimal Octal

Binary Hexadecimal
Hexadecimal to Binary Conversion

• Technique
• Convert each hexadecimal digit to a 4-bit equivalent binary
representation
Example
10AF16 = ?2

1 0 A F

0001 0000 1010 1111

10AF16 = 00010000101011112
Convert 3EF.2C into binary
(3EF.2C) 16= (?) 2

3 E F . 2 C

0011 1110 1111 . 0010 1100

(3EF.2C) 16= (0011 1110 1111 . 0010 1100) 2


11. Octal to Hexadecimal

Decimal Octal

Binary Hexadecimal
Octal to Hexadecimal

• Technique
• Use binary as an intermediary
• For this octal number is converted into binary number.
• Then groups of 4 binary numbers are formed.
• And it is converted into hexadecimal number.
Example
10768 = ?16

1 0 7 6
1. Octal to binary conversion

Group of 3 binary nos. 001 000 111 110


2. Regroup into 4 binary nos. (0010) (0011) (1110)
3. Binary to Hexadecimal conversion 2 3 E

10768 = 23E16
12. Hexadecimal to Octal

Decimal Octal

Binary Hexadecimal
Hexadecimal to Octal

• Technique
• (Use binary as an intermediary)
• For this first hexadecimal number is converted into
binary.
• Then group of 3 are formed.
• Then it is converted into octal.
Example

1F0C16 = ?8
1 F 0 C
1. Hexadecimal to binary conversion

Group of 4 binary nos. 0001 1111 0000 1100


2. Regroup into 3 binary nos. 001 111 100 001 100
3. Binary to Octal conversion 1 7 4 1 4

1F0C16 = 174148
Table (1 of 3)
Hexa-
Decimal Binary Octal decimal
0 0 0 0
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
6 110 6 6
7 111 7 7
Table (2 of 3)

Hexa-
Decimal Binary Octal decimal
8 1000 10 8
9 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
Table (3 of 3)

Hexa-
Decimal Binary Octal decimal
16 10000 20 10
17 10001 21 11
18 10010 22 12
19 10011 23 13
20 10100 24 14
21 10101 25 15
22 10110 26 16
23 10111 27 17
Conversions:
1. Decimal to Binary 7. Binary to octal
2. Binary to decimal 8. Binary to hexadecimal
3. Decimal to octal 9. Octal to hexadecimal
4. Octal to decimal 10. Octal to binary
5. Decimal to hexadecimal 11. Hexadecimal to octal
6. Hexadecimal to decimal 12. Hexadecimal to binary
Examples:
1. Decimal to Binary : 267 =
2. Binary to decimal : 1011.1101 =
3. Decimal to octal : 986 =
4. Octal to decimal : 654 =
5. Decimal to hexadecimal : 267 =
6. Hexadecimal to decimal : ABC =
Examples:
7. Binary to octal : 1011.1101 =
8. Binary to hexadecimal : 101101.101101 =
9. Octal to hexadecimal : 432 =
10. Octal to binary : 675 =
11. Hexadecimal to octal: 12AB =
12. Hexadecimal to binary: 11CD =
Arithmetic operation with binary number:
Binary addition:

Number Sum Carry


A B A+B
0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1
Example: Binary Addition
• Carries 00000 01100
• Augend 01100 10110
• Addend +10001 +10111
• Sum 11101 101101
Binary subtraction:

Number Difference Borrow


A B A-B
0 0 0 0
0 1 1 1
1 0 1 0
1 1 0 0
Example: Binary Subtraction
• Borrows 00000 00110
• Minuend 10110 10110
• Subtrahend –10010 –10011
• Difference 00100 00011
Binary Multiplication
The binary multiplication table is simple:
00=0 | 10=0 | 01=0 | 11=1
Extending multiplication to multiple digits:
Multiplicand 1011
Multiplier x 101
Partial Products 1011
0000 -
1011 - -
Product 110111
• 1’s and 2’s complements of binary numbers:
-1’s complement:

-In binary, complement of 0 is 1 and complement of 1 is 0.


-1’s complement of a binary number is complement of each bit.

-If we take 8 bit number, 1’s complement of 1011 0111 is 0100


1000.
-If we take fractional number, 1’s complement of 1000.1101 is
0111.0010
• 2’s complement:
2’s complement of number:
- 1’s complement of that number is found
- 1 is added to it.

2’s complement = 1’s complement+1


e.g.
1101
1’s complement of 1101 is 0010
adding 1 + 1
0011
Example: Find 2’s complement of 101101

101101
010010 (1’s complement)
+ 1 (Add 1)
010011 (2’s complement)
BINARY SUBTRACTION USING 1’S COMPLEMENT:
A) When smaller number has to be subtracted from large number:

1. Write 1’s complement of smaller number.


2. Add this to the large number.
3. Add end around carry to the sum.

E.g. Subtract (1010)2 from (1100)2


1100
+ 0101
1 0001
+ 1
0010
B) When larger number has to be subtracted from smaller number:

1. Write 1’s complement of bigger number.


2. Add it to the smaller number.
3.The result is 1’s complement of the answer and of opposite sign.
there is no carry.
4. To get the answer take 1’s complement of the results.

E.g. (1001)2 - (1101)2


1001
+ 0010
1011
(1001)2 - (1101)2 = (-0100)2
BINARY SUBTRACTION USING 2’S COMPLEMENT:
A) When number to be subtracted is smaller:

1.Write 2’s complement of smaller number.


2. Add it to the large number.
3. Avoid carry. (In this always carry is there)

E.g. Subtract (0100)2 from (1101)2.

1011 1101
+ 1 + 1100
1100 11001
avoid carry (1001) 2
B) When number to be subtracted is larger:

1. Take 2’s complement of bigger number.


2. Add it to the smaller number.
3.The result is in form of 2’s complement of the answer. There is no
carry.
4. Take 2’s complement of the results & a sign negative sign.

E.g. (1001)2-(1101)2

0010 1001
+ 1 +0011
0011 1100
0011+1=0100 is (-100)2
9’s and 10’s complement:
- These are the complements in decimal number system.
- To find 9’s complement of a decimal number system, each
decimal digit is subtracted from 9.

E.g. Find 9’s complement of(307)10

999
- 307
692
10’s complement of decimal number can be found by adding 1 to the 9’s
complement of that number.
10’s complement = 9’s complement + 1

E.g. Find 10’s complement of (572)10

999
-572
427 (9’s complement)
+ 1 (Add 1)
428 (10’s complement)
Subtraction using 10’s complement
• A) When number to be subtracted is smaller:
1.Write 10’s complement of smaller number.
2. Add it to the large number.
3. Avoid carry. (In this always carry is there)

• Using 10’s complement, subtract 72532 - 03250.


M= 72532
10>s complement of N = + 96750
Sum = 169282
Discard end carry = - 100000
Answer = 69282
Subtraction using 10’s complement
• B) When number to be subtracted is larger:
1. Take 10’s complement of bigger number.
2. Add it to the smaller number.
3.The result is in form of 10’s complement of the answer. There is no carry.
4. Take 2’s complement of the results & a sign negative sign.
• Using 10’s complement, subtract 3250 - 72532.
M = 03250
10>s complement of N = + 27468
Sum = 30718
There is no end carry. Therefore, the answer is -(10>s complement of 30718)
= -69282.
Binary Coded Decimal (BCD)
• The BCD code is the 8,4,2,1 code.
• This code is the simplest, most intuitive binary code for decimal digits
and uses the same powers of 2 as a binary number, but only encodes
the first ten values from 0 to 9.
• Example: 1001 (9) = 1000 (8) + 0001 (1)
BCD Arithmetic
Given a BCD code, we use binary arithmetic to add the digits:
8 1000 Eight
+5 +0101 Plus 5
13 1101 is 13 (> 9)
Note that the result is MORE THAN 9, so must be represented by two digits!
To correct the digit, subtract 10 by adding 6 modulo 16.
8 1000 Eight
+5 +0101 Plus 5
13 1101 is 13 (> 9)
+0110 so add 6
carry = 1 0011 leaving 3 + cy
0001 | 0011 Final answer (two digits)
If the digit sum is > 9, add one to the next significant digit
Warning: Conversion or Coding?

• Do NOT mix up conversion of a decimal number to a binary number


with coding a decimal number with a BINARY CODE.
• 1310 = 11012 (This is conversion)
• 13  0001|0011 (This is coding)
Binary Codes
• Codes are used for data in digital system (number, alphabets
punctuation etc).
• These codes are also in binary numbers.
• To detect the error, error detecting code is necessary
• To correct the error, error correcting code is necessary.
• Codes are used to show different numerals and alphanumeric
characters to detect and correct error in data transmission and
reception.
• Types of codes:

1. Weighted binary code.


2. Non weighted binary code.
3. Alphanumeric code.
4. Error detecting code.
5. Error correcting code.
Weighted binary code:
• There is specific weightage to each position of the digit.
• We get the value by multiplying the digit by the weightage and
making sum.
• Types :
a) Straight binary code
E.g.25=11001
b) Natural BCD code or 8421
E.g. 25=0010 0101
c) 2421 code (5421, 7421, 6311, 4221, 3321)
Non-weighted binary codes:
a) Excess-3 code(self-complementing code)
b) Gray code (unit distance code, cyclic code, reflected code)

a) Excess-3 code(self-complementing code)


To convert any decimal digit into excess-3, 3 is added to that
decimal digit and excess-3 code is found.

To convert any excess-3 code into decimal, 3 is subtracted to


that Excess-3 and decimal number is found.
Binary Codes for Decimal Digits
There are over 8,000 ways that you can chose 10 elements
from the 16 binary numbers of 4 bits. A few are useful:

Decimal 8,4,2,1 Excess3 8,4,-2,-1 Gray


0 0000 0011 0000 0000
1 0001 0100 0111 0100
2 0010 0101 0110 0101
3 0011 0110 0101 0111
4 0100 0111 0100 0110
5 0101 1000 1011 0010
6 0110 1001 1010 0011
7 0111 1010 1001 0001
8 1000 1011 1000 1001
9 1001 1100 1111 1000
E.g. (1): Find excess-3 of (5)10

5
+ 3 (Add 3)
8 (Find binary of 8)
(1000)Ex-3

(2) Given (1100)Ex-3 find decimal equivalent.

12
- 3 (Subtract 3)
9
Examples:
• Find BCD code of (83)10 • Find excess-3 code of (1532)10
(83)10 (1 5 3 2)10

1000 0011 0001 0101 0011 0010


+0011 0011 0011 0011
0100 1000 0110 0101
b) Conversion of binary number to gray:
1. Write binary number
2. Write MSB of binary number as MSB of gray code
3. Add this MSB to the binary number next to the MSB
4. Avoiding carry continue the process until LSB is reached.

E.g. (1001101)2 = (1101011)gray


Conversion of gray code to binary:
1. Write gray code
2. Write MSB of gray code as MSB of binary.
3. Add this MSB to the significant digit before MSB of the gray code
4. Avoid carry and write the sum as the significant digit before MSB
of binary
5. Repeat process until LSB is reached

E.g. (10001101)gray = (11110110)2


Self-complementing type:
Complement of binary equivalent of a decimal digit is 9’s
complement of decimal. 9’s complement of decimal number can be
obtained by subtracting that number from 9.

E.g. 2421 code of decimal number 7 is 1101.


It’s 1’s complement is 0010 which is 2421 code of decimal number 2
and 2 is 9’s complement of decimal number 7.
Sequential code:
The code in which if each successive code is one binary number more
than its preceding code is called the sequential code.
E.g. 8421 ,Excess-3 code etc . Whereas 2421,5211 are not sequential
code.

Reflective code:
The code in which code of 9 is the complement of the code for
0,code of 8 is the complement of the code for 1and so on is called
the reflective code.
E.g. 2421, 5211, etc.
Alpha-numeric code:
In computers in addition to the numbers, letters(upper case and
lower case),signs, mathematical signs, punctuations etc. are also
used. code is also needed for all these. For this alpha-numeric code is
developed. There are three types of alpha-numeric code:

1. ASCII code(American Standard Code for Information Interchange )


2. EBCDIC code(Extended Binary Coded Decimal Information Code)
3. Hollerith code
Error detecting code:
• Error detecting code is used to check whether there is error in received
data. For this parity bit is used.
This data is of 7 bits and 1 parity bit is added, so there are total 8 bits data.
Parity bit is added to the left of MSB of the data . There are two types of
parity used.
1) Odd parity
2) Even parity
A code word has even parity if the number of 1’s in the code word is
even.
A code word has odd parity if the number of 1’s in the code word is odd.
Odd parity:

Parity bit data bit


1 1000111 : four 1’s i.e. even, so parity bit is 1
0 0001110 : three 1’s i.e. odd, so parity bit is 0

Even parity:

parity bit data bit


1 1010111 : five 1’s i.e. odd, so parity bit is 1
0 0110110 : four 1’s i.e. even, so parity bit is 0
Error correcting code:
• Error correcting code:

This type of code was developed by R.W.Hamming, so it is known as


the hamming code.
THANK YOU

You might also like