Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
18 views36 pages

Digital Logic Design - CH 2

part 2 of the preveius

Uploaded by

gebresilasie777
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)
18 views36 pages

Digital Logic Design - CH 2

part 2 of the preveius

Uploaded by

gebresilasie777
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/ 36

Digital Logic Design

Chapter 2
Number System,
Operations and Codes

Content
• Decimal Numbers
• Binary Numbers
• Binary to Decimal Conversion
• Decimal to Binary Conversion
• Binary Arithmetic
• 1'S AND 2’S Complement of Binary Numbers
• Signed Binary Number
• Arithmetic Operations with Signed Numbers
• Hexadecimal Number
• Octal Number
• Binary Codded Decimal(BCD)
• Digital Code

1
Digital Logic Design

Decimal Numbers

• Decimal Number System is Composed of 10 numerals or


symbols.
• These 10 symbols are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9;
• Using these 10 symbols as digits of a number, we can
express any quantity.
• The decimal system, also called the base-10 system because
it has 10 digits.
• The position of each digit in a decimal number indicates the
magnitude of the quantity represented and can be assigned
a weight.

Cont.

• The weights for whole numbers are positive powers of ten


that increase from right to left, beginning with 10° = 1.
• For fractional numbers, the weights are negative powers of
ten that decrease from left to right beginning with 10-1.

• The value of a decimal number is the sum of the digits after


each digit has been multiplied by its weight.

2
Digital Logic Design

Cont.…
• Example1:-

• Example 2:- Express the decimal number 568.23 as a sum of the


values of each digit.

Binary Numbers

• The binary number system has two digits (bits).


• The two binary digits (bits) are 1 and 0.
• The position of a 1 or 0 in a binary number indicates its
weight.
• The weights in a binary number are based on powers of
two.
• The right-most bit is the LSB (least significant bit) in a binary
whole number and has a weight of 2° = 1.

3
Digital Logic Design

Cont.
• The weights increase from right to left by a power of two for
each bit.
• The left-most bit is the MSB (most significant bit).
• The left-most bit is the MSB in a binary fractional number
and has a weight of 2-1= 0.5.
• The fractional weights decrease from left to right by a
negative power of two for each bit.
• Generally, the weight structure of a binary number is
• where n is the number
of bits from the binary
point.

Decimal Binary
Binary Counting Number

0
Number

0000
1 0001
• A binary counting sequence for numbers 2 0010
from zero to fifteen is shown. 3 0011
4 0100
• Notice the pattern of zeros and ones in 5 0101
each column. 6 0110
7 0111
• Digital counters frequently have this
8 1000
same pattern of digits: 9 1001
Counter 0 1 0 1 0 1 0 1 0 1 Decoder
10 1010
0 0 1 1 0 0 1 1 0 0
11 1011
12 1100
0 0 0 0 1 1 1 1 0 0
13 1101
0 0 0 0 0 0 0 0 1 1
14 1110
15 1111

4
Digital Logic Design

Exercise
• Find the binary value of the decimal number 122

Binary Counting
• With n bits we can represent decimal numbers
from 0 to 2n – 1.
• How many bits do we need to conunt(represent) N
decimal numbers in a binary?
𝑛 ≥ log 𝑁
Where n is the numbers of bit needed (it is positive
integre)
• How many decimal numbers can we represent with
n bits binary number?
𝑁=2

10

5
Digital Logic Design

11

Binary to Decimal Conversion

• The decimal value of any binary number can be found by


adding the weights of all bits that are 1 and discarding the
weights of all bits that are 0.
• Example:-Convert the binary whole number 1101101 to
decimal

12

6
Digital Logic Design

Cont.

• Example 2:- Convert the fractional binary number 0.1011 to


decimal.

• Ex :-

13

Decimal to Binary Conversion

a. Sum-of-Weights Method
• One way to find the binary number that is equivalent to a given
decimal number is to determine the set of binary weights whose
sum is equal to the decimal number.
Convert the decimal number 49 to binary.
The column weights double in each position to the right. Write
down column weights until the last number is larger than the
one you want to convert.
26 25 24 23 22 21 20.
64 32 16 8 4 2 1.
0 1 1 0 0 0 1.
Example:- Convert the following decimal numbers to binary:
a) 12 b)25 c)58 d)72
14

7
Digital Logic Design

Decimal to Binary Conversion

b. Repeated Division-by-2 Method


• To get the binary number for a given decimal number, divide
the decimal number by 2 until the quotient is 0.
• Note the remainders form the binary number.
• The first remainder to be produced is the LSB in the binary
number, and the last remainder to be produced is the MSB.
• Example:- Convert the following decimal numbers to binary:

15

Repeated Division-by-2 Method

Repeated
Division
Divide the decimal
number by 2.
Write the remainder
after each division
until a quotient of
zero is obtained.
The first remainder
is the LSB.
The last is the MSB.

16

8
Digital Logic Design

Converting Decimal Fractions to Binary

• Sum-of-Weights:-The sum-of-weights method can be applied


to fractional decimal numbers, as shown in the following
example:

• Repeated Multiplication by 2 :-Decimal fractions can be


converted to binary by repeated multiplication by 2.
• Multiplying each resulting fractional part of the product by 2
until the fractional product is zero or until the desired
number of decimal places is reached.

17

Converting Decimal Fractions to Binary

• The carry digits, or carries, generated by the multiplications


produce the binary number.
• The first carry produced is the MSB, and the last carry is the
LSB.
Convert the decimal fraction 0.188 to binary by
repeatedly multiplying the fractional results by 2.

0.188 x 2 = 0.376 carry = 0 MSB


0.376 x 2 = 0.752 carry = 0
0.752 x 2 = 1.504 carry = 1
0.504 x 2 = 1.008 carry = 1
0.008 x 2 = 0.016 carry = 0
Answer = .00110 (for five significant digits)
18

9
Digital Logic Design

Converting Decimal Fractions to Binary

• Example:-Convert each decimal number to binary by using


the repeated multiplication-by-2 for fractions.
a) 0.625 b) 0.375

19

Binary Arithmetic
Binary Addition
The rules for binary addition are
0+0=0 Sum = 0, carry = 0
0+1=1 Sum = 1, carry = 0
1+0=1 Sum = 1, carry = 0
1 + 1 = 10 Sum = 0, carry = 1
When an input carry = 1 due to a previous result, the rules
are
1 + 0 + 0 = 01 Sum = 1, carry = 0
1 + 0 + 1 = 10 Sum = 0, carry = 1
1 + 1 + 0 = 10 Sum = 0, carry = 1
1 + 1 + 1 = 11 Sum = 1, carry = 1

20

10
Digital Logic Design

Binary Arithmetic
Binary Addition
Add the binary numbers 00111 and 10101 and show
the equivalent decimal addition.
0111
00111 7
10101 21
11100 = 28
Add the following binary numbers
(a) 11+11 (b) 100+10 (c) 111+11 (d) 110+100

21

Binary Arithmetic
Binary Subtraction
The four rules for binary subtraction of bits are
0-0=0
1-1=0
1-0=1
10 - 1 = 1 0-1,with a borrow of 1
Subtract the binary number 00111 from 10101 and
show the equivalent decimal subtraction.
111
10101
/ / / 21
00111 7
01110 = 14

22

11
Digital Logic Design

Example

23

Binary Arithmetic
Binary Subtraction
Perform the following binary subtraction:
(a) 11 - 01 (b) 11 - 10

24

12
Digital Logic Design

Binary Arithmetic
Binary Multiplication
The four basic rules for multiplying bits are as follows:
0*0=0
0*1=0
1*0=0
1*1=1
Perform the following binary multiplications:
(a) 11 * 11 (b) 101 * 111

25

Binary Arithmetic
Binary Division
Division in binary follows the same procedure as division in
decimal.

Perform the following binary divisions:


(a) 110 ÷ 11 (b) 110 ÷ 10

26

13
Digital Logic Design

1'S AND 2’S Complement of Binary Numbers

• The 1's complement and the 2's complement of a binary


number are important because they permit the
representation of negative numbers.
• The method of 2's complement arithmetic is commonly
used in computers to handle negative numbers.

27

1’S Complement

• The 1’s complement of a binary number is just the


inverse of the digits. To form the 1’s complement,
change all 0’s to 1’s and all 1’s to 0’s.
• For example, the 1’s complement of 11001010
is 00110101
• In digital circuits, the 1’s complement is formed by using
inverters:
1 1 0 0 1 0 1 0

0 0 1 1 0 1 0 1
28

14
Digital Logic Design

2’S Complement

The 2’s complement of a binary number is found by


adding 1 to the LSB of the 1’s complement.
Recall that the 1’s complement of 11001010 is
00110101 (1’s complement)
To form the 2’s complement, add 1: +1
1 1 0 0 1 0 1 0 00110110 (2’s complement)

1
0 0 1 1 0 1 0 1
Input bits
Carry
Adder
in (add 1)
Output bits (sum)

0 0 1 1 0 1 1 0

29

2’S Complement

30

15
Digital Logic Design

Signed Binary Numbers

• Digital systems, such as computers, 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 a number is positive or negative,
and the magnitude is the value of the number.

31

Signed Binary Numbers


• There are three forms in which signed integer (whole)
numbers can be represented in binary:
a. Sign-magnitude,
b. 1's complement, and
c. 2' complement.
• Of these, the 2's complement is the most important and the
sign-magnitude is the least used.
• The Sign Bit:- the left-most bit in a signed binary number is
the sign bit, which tells you whether the number is positive
or negative.
• A 0 sign bit indicates a +ve number, and a 1 sign bit indicates
a –ve number.

32

16
Digital Logic Design

Sign-Magnitude Form
• When a signed binary number is represented in sign-
magnitude, 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 example, the decimal number + 25 is expressed as an 8-
bit signed binary number using the sign-magnitude form as

• Notice that the only difference between + 25 and - 25 is the


sign bit.

33

1' s Complement Form

• Positive numbers in 1's complement form are represented the same


way as the positive sign-magnitude numbers.
• Negative numbers, however, are the 1's complements of the
corresponding positive numbers.
• For example:- using eight bits, the decimal number -25 is expressed as
the 1's complement of +25 (00011001 ) as 11100110

34

17
Digital Logic Design

2’s Complement Form


• Positive numbers in 2's complement form are represented
the same way as in the sign-magnitude and 1's complement
forms.
• Negative numbers are the 2's complements of the
corresponding positive numbers.
• Again, using eight bits, let's take decimal number -25 and
express it as the 2's complement of
+25 (00011001) 111O0111
• In the 2's complement form, a negative number is the 2's
complement of the corresponding positive number.

35

Cont.…
Example
Express the decimal number -39 as an 8-bit number in the
a) sign-magnitude
b) 1's complement, and
c) 2's complement forms.

36

18
Digital Logic Design

Four-Bit Signed Binary Numbers in Sign–Magnitude, One’s Complement,


and Two’s Complement

37

Hexadecimal Numbers Decimal Hexadecimal Binary


0 0 0000
1 1 0001
Hexadecimal uses sixteen characters to 2 2 0010
represent numbers: the numbers 0 3 3 0011
through 9 and the alphabetic characters 4 4 0100
A through F. 5 5 0101
6 6 0110
7 7 0111
8 8 1000
9 9 1001
10 A 1010
11 B 1011
12 C 1100
13 D 1101
14 E 1110
15 F 1111

38

19
Digital Logic Design

Binary-to-Hexadecimal Conversion

• Large binary number can easily be converted to


hexadecimal by grouping bits 4 at a time and writing the
equivalent hexadecimal character.
• Simply break the binary number into 4-bit groups, starting
at the LSB and replace each 4-bit group with the equivalent
hexadecimal symbol.

39

Hexadecimal-to-Binary Conversion

• To convert from a hexadecimal number to a binary number,


reverse the process and replace each hexadecimal symbol
with the appropriate four bits.
• Hexadecimal is a convenient way to represent binary
numbers.

40

20
Digital Logic Design

Hexadecimal-to-Decimal Conversion

• One way to find the decimal equivalent of a hexadecimal


number is to first convert the hexadecimal number to binary
and then convert from binary to decimal.

• Another is to multiply the decimal value of each


hexadecimal digit by its weight and then take the sum of
these products.
• Example:-Convert the following hexadecimal numbers to
decimal:

41

Hexadecimal Addition

• Addition can be done directly with hexadecimal numbers as the


following example
• Example:- Add the following hexadecimal numbers:

42

21
Digital Logic Design

Hexadecimal Subtraction

• Convert the hexadecimal number to binary. Take the 2's complement of


the binary number. Convert the result to hexadecimal.
• Example:- Subtract the following hexadecimal numbers:

43

OCTAL NUMBERS

 The octal number system is composed of eight digits.


 These are 0, 1, 2, 3, 4, 5, 6, 7.
 The octal number system has a base of 8.
Octal-to-Decimal Conversion
 The evaluation of an octal number in terms of its decimal equivalent is
accomplished by multiplying each digit by its weight and summing the
products.
 Example: Convert (127.4)8 to Decimal
Solution:
(127.4)8 = 1x82 + 2x81 + 7x80 + 4x8-1 = (87.5)10

44

22
Digital Logic Design

45

Octal-to-Binary Conversion
 Because each octal digit can be represented by a 3-bit
binary number, it is very easy to convert from octal to
binary.

46

23
Digital Logic Design

OCTAL TO BINARY

 To convert an octal number to a binary number, simply


replace each octal digit with the appropriate three bits.
 Example:-
 Convert each of the following octal numbers to binary:

47

Binary-to-Octal Conversion

 Conversion of a binary number to an octal number is the reverse of the


octal-to-binary conversion.
 Start with the right-most group of three bits and, moving from right to
left, convert each 3-bit group to the equivalent octal digit.
 Example:-Convert each of the following binary numbers to octal:

48

24
Digital Logic Design

Exercise

49

Human Perception
• We naturally live in a base 10 environment(decimal number
system)
• Computer exist in a base 2 environment(binary number system)
• So give the computer/digital system the task of doing the
conversions for us.

50

25
Digital Logic Design

Binary Codes
• “An n-bit binary code is a group of n bits that assume up to
2n distinct combinations of 1s and 0s, with each
combination representing one element of the set being
coded”
• For the 10 digits need a 4 bit code.
• The four bits code representation of decimal number is
called Binary Coded Decimal (BCD)

51

Binary Coded Decimal (BCD)


• Binary coded decimal means that each decimal digit, 0
through 9, is represented by a binary code of four bits.
• Binary coded decimal (BCD) is a weighted code that is
commonly used in digital systems when it is necessary to show
decimal numbers such as in clock displays.
• The 8421 code is a type of BCD (binary coded decimal) code.
• The designation 8421 indicates the binary weights of the four
bits (23 , 22 , 21 ,20 )

• Invalid Codes:-The six code combinations that are not used in


BCD
 1010, 1011, 1100, 1101, 1110, and 1111:-are invalid in the 8421 BCD code..

52

26
Digital Logic Design

BCD Decimal Binary BCD

• The table illustrates the difference 0 0000 0000


between straight binary and BCD. 1 0001 0001
2 0010 0010
• BCD represents each decimal digit 3 0011 0011
with a 4-bit code. 4 0100 0100
• Notice that the codes 1010 through 5 0101 0101
1111 are not used in BCD. 6 0110 0110
7 0111 0111
8 1000 1000
9 1001 1001
10 1010 0001 0000
11 1011 0001 0001
12 1100 0001 0010
13 1101 0001 0011
14 1110 0001 0100
15 1111 0001 0101

53

Decimal to BCD
• To express any decimal number in BCD, simply replace each
decimal digit with the appropriate 4-bit code, as shown by
Example:
• Example:-Convert each of the following decimal numbers to
BCD: (a) 35 (b)98 (c) 170 (d)2469

54

27
Digital Logic Design

BCD to Decimal
 It is equally easy to determine a decimal number from a BCD
number.
 Start at the right most bit and break the code into groups of four
bits.
 Then write the decimal digit represented by each 4-bit group.
 Example:-Convert each of the following BCD codes to decimal:

55

Digital Codes
• Many specialized codes are used in digital systems.
• You have just learned about the BCD code; now let's look at a few
others.
• Some codes are strictly numeric, like BCD, and others are
alphanumeric; that is, they are used to represent numbers,
letters, symbols, and instructions.
• The codes introduced in this section are
 The Gray code
 The ASCII code and

56

28
Digital Logic Design

Gray Code
• The Gray code is unweighted and is not an arithmetic code; that is,
there are no specific weights assigned to the bit positions.
• The important feature of the Gray code is that it exhibits only a
single bit change from one code word to the next in sequence.
• Like binary numbers, the Gray code can have any number of bits.
Notice the single-bit change between successive Gray code words.
• Gray code is used to avoid problems in systems where an error
can occur if more than one bit changes at a time.
• This property is important in many applications, such as shaft
position encoders, where error susceptibility increases with the
number of bit changes between adjacent numbers in a sequence.

57

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.

Binary sequence
Gray code sequence

58

29
Digital Logic Design

Gray Code Decimal Binary Gray code


0 0000 0000
The following table is listing of the 1 0001 0001
4-bit Gray code for decimal 2 0010 0011
numbers 0,1,2,…15. 3 0011 0010
4 0100 0110
5 0101 0111
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

59

60

30
Digital Logic Design

Binary-to-Gray Code Conversion


• The following rules explain how to convert from a binary number to a
Gray code word:
1. The most significant bit (left-most) in the Gray code is the same as
the corresponding MSB in the binary number.
2. Going from left to right, add each adjacent pair of binary code bits
to get the next Gray code bit. Discard carries.

61

Gray-to-Code Binary Conversion


• Gray-to-Binary Conversion to convert from Gray code to
binary, use a similar method; however, there are some
differences.
• The following rules apply:
1. The most significant bit (left-most) in the binary code is
the same as the corresponding bit in the Gray code.
2. Add each binary code bit generated to the Gray code bit
in the next adjacent position. Discard carries.

62

31
Digital Logic Design

a) Binary to Gray b) Gray to Binary

63

Cont.…

64

32
Digital Logic Design

65

Alphanumeric Codes
• Alphanumeric codes are codes that represent numbers and
alphabetic characters (letters).
• Most such codes, however, also represent other characters
such as symbols and various instructions necessary for
conveying information that are found on a computer
keyboard.
• The ASCII is the most common alphanumeric code.
• ASCII:-is the abbreviation for American Standard Code for
Information Interchange.

66

33
Digital Logic Design

ASCII
 ASCII is a universally accepted alphanumeric code used in most
computers and other electronic equipment.
 Most computer keyboards are standardized with the ASCII.
 When you enter a letter, a number, or control command, the
corresponding ASCII code goes into the computer.
 ASCII has 128 characters and symbols represented by a 7-bit binary
code.
 Actually, ASCII can be considered an 8-bit code with the MSB always 0.
This 8-bit code is 00 through 7F in hexadecimal.
 The following table is a listing of partial ASCII code showing the decimal,
hexadecimal, and binary representations for each character and symbol.

67

68

34
Digital Logic Design

Cont.…
• Example:- The following is a message encoded in ASCII code. What is
the message? 1001000 1000101 1001100 1010000
• Solution:- Convert each seven-bit code to its hex equivalent.
• The results are 48 45 4C 50
• Now locate these hex values in Table above and determine the
character represented by each. The results are HELP

• Example2: write your full name using ASCII Code.


• Example3:

69

Extended ASCII
• 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.

70

35
Digital Logic Design

Parity Method
• The parity method is a method of error detection for
simple transmission errors involving one bit (or an odd
number of bits).
• A parity bit is an “extra” bit attached to a group of bits
to force the number of 1’s to be either even (even
parity) or odd (odd parity).
The ASCII character for “a” is 1100001 and for “A” is
1000001. What is the correct bit to append to make both of
these have odd parity?

The ASCII “a” has an odd number of bits that are equal to 1;
therefore the parity bit is 0. The ASCII “A” has an even
number of bits that are equal to 1; therefore the parity bit is 1.

71

36

You might also like