You are on page 1of 31

Logic Design

Some slides are taken from


Floyd, Digital Fundamentals, 10th ed 2009 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved

1
Lecture 1

Number Systems, Operations, and


Codes

2
Number Systems

A numbering system has a number of digits and a base.


The digits run from 0 to B-1 where B is the base.
Each digit has a weight, W depending on its position
within the number.

System Base Digits


Binary 2 01
Octal 8 01234567
Decimal 10 0123456789
Hexadecimal 16 0123456789
ABCDEF

3
Number Base Conversion

From Decimal to any base Example 1 Decimal to


Integer Binary
1. Divide the decimal Number Base Quotient remainder
number by the base 13 2 6 1
2. Divide the quotient with
6 2 3 0
the base
3 2 1 1
3. Repeat step 2 until the
remainder is 0 1 2 0 1

1310 = 11012

4
Number Base Conversion

From Decimal to any base Example 2 Decimal to Octal


Integer
1. Divide the decimal Number Base Quotient remainder
number by the base
113 8 14 1
2. Divide the quotient with
the base 14 8 1 6

3. Repeat step 2 until the 1 8 0 1


remainder is 0

11310 = 1618

5
Number Base Conversion

From Decimal to any base Example 3 Decimal to


Integer Hexadecimal
1. Divide the decimal Number Base Quotient Remainder
number by the base
126 16 7 14
2. Divide the quotient with 7 16 0 7
the base
3. Repeat step 2 until the
remainder is 0

12610 = 7E16

6
Number Base Conversion

From Decimal to any base Example 1 Decimal to


Fraction Binary
1. Multiply the decimal Number Base Integer Fraction
Number by the base 0.35 2 0 0.7
2. Multiply the fraction with 0.7 2 1 0.4
the base 0.4 2 0 0.8
3. Repeat step 2 until the 0.8 2 1 0.6
fraction is 0 OR the 0.6 2 1 0.2
fraction is repeated OR 0.2 2 0 0.4
the number of required
digits is achieved 0.3510 = 0.0101102

7
Number Base Conversion

From Decimal to any base Fraction


Example 1 Decimal to
Binary Number Base Integer Fraction
20.3510 = ?2 0.35 2 0 0.7
Integer 0.7 2 1 0.4

Number Base Quotient Remainder 0.4 2 0 0.8

20 2 10 0 0.8 2 1 0.6

10 2 5 0 0.6 2 1 0.2

5 2 2 1 0.2 2 0 0.4

2 2 1 0
20.3510 = 10100.0101102
1 2 0 1

8
Number Base Conversion

From any base to Decimal Example 1 Hexadecimal to


Decimal
2 1 0 -1 -2 -3
1 9 3 . 2 4 5 A3.5C16 = ?10
W 1 0 -1 -2
1. Multiply each digit by the
No A 3 . 5 C
base raised to the power
of its weight Res 10* 3* 5* 12*
161 160 16-1 16-2
2. Add the results obtained 160 3 0.31 0.04
in 1 above to get the 25 6875
equivalent value in
decimal. 160+3+0.3125+0.046875 = 163.359375

A3.5C16 = 163.35937510

9
Number Base Conversion

From any base to Decimal Example 2 Octal to Decimal


2 1 0 -1 -2 -3 73.568 = ?10
1 9 3 . 2 4 5

W 1 0 -1 -2
1. Multiply each digit by the
No 7 3 . 5 6
base raised to the power
of its weight Res 7* 3* 5*8-1 6* 8-2
81 80
2. Add the results obtained 56 3 0.62 0.093
in 1 above to get the 5 75
equivalent value in
decimal. 56+3+0.625+0.09375 = 59.71875

73.568 = 59.7187510

10
Number Base Conversion
Decimal Hexadecimal Binary
From Binary to Hexadecimal 0 0 0000
1. Starting at the binary 1 1 0001
point, group every four 2 2 0010
3 3 0011
binary bits into one 4 4 0100
group 5 5 0101
2. Convert each group into 6 6 0110
their hexadecimal 7 7 0111
8 8 1000
equivalent. 9 9 1001
Example 10 A 1010
11 B 1011
10 0100 1010.1100 10
12 C 1100
2 4 A . C 8 13 D 1101
14 E 1110
15 F 1111

11
Number Base Conversion
Decimal Hexadecimal Binary
From Hexadecimal to Binary 0 0 0000
1. Starting at the 1 1 0001
hexadecimal point, 2 2 0010
3 3 0011
convert each 4 4 0100
hexadecimal number into 5 5 0101
its equivalent four binary 6 6 0110
bits 7 7 0111
8 8 1000
Example 9 9 1001
10 A 1010
A F C . 3 B 11 B 1011
1010 1111 1100 . 0011 1011 12 C 1100
13 D 1101
14 E 1110
15 F 1111

12
Number Base Conversion

From Binary to Octal Decimal Octal Binary


0 0 000
1. Starting at the binary 1 1 001
point, group every three 2 2 010
binary bits into one 3 3 011
group 4 4 100
5 5 101
2. Convert each group into 6 6 110
their Octal equivalent. 7 7 111
Example
1 101 011 010.110 010
1 5 3 2 .6 2

13
Number Base Conversion

From Octal to Binary Decimal Octal Binary


0 0 000
1. Starting at the Octal 1 1 001
point, convert each octal 2 2 010
number into its 3 3 011
equivalent three binary 4 4 100
bits 5 5 101
6 6 110
Example 7 7 111

6 3 2 . 3 1
110 011 010 . 011 001

14
Signed Numbers

Signed numbers can be 7 is positive while -7 is


both positive and negative
negative 7 is represented
In computers, the most 00000111 in a 8 bit
significant bit (MSB) is binary system while -7 is
used to represent sign. A represented as 1xxxxxxx
0 indicates a positive no
and 1 indicates a
negative no
There are 3 methods for
representing negative
numbers

15
Signed Numbers

Sign-Magnitude -7 is represented as
The MSB is the sign and the 10000111
rest is the absolute value of
the number
1s Complement 0 0 0 0 0 1 1 1
1 1 1 1 1 0 0 0
Each 0 in the positive
number is converted into 1
and each 1 into 0
2s Complement 0 0 0 0 0 1 1 1

Is obtained by adding 1 to 1 1 1 1 1 0 0 0

the 1s complement + 1

1 1 1 1 1 0 0 1

16
Summary
Binary Addition

The rules for binary addition are


0 + 0 = 0 Sum = 0, carry = 0
0 + 1 = 0 Sum = 1, carry = 0
1 + 0 = 0 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

Floyd, Digital Fundamentals, 10th ed 2009 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved
Summary
Binary Addition

Add the binary numbers 00111 and 10101 and


show the equivalent decimal addition.
0111
00111 7
10101 21
11100 = 28

Floyd, Digital Fundamentals, 10th ed 2009 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved
Summary
Binary Subtraction

The rules for binary subtraction are


0-0=0
1-1=0
1-0=1
10 - 1 = 1 with a borrow of 1

Subtract the binary number 00111 from 10101 and show the
equivalent decimal subtraction.

1 1 1
10101
/ / / 21
00111 7
0 1 1 1 0 = 14

Floyd, Digital Fundamentals, 10th ed 2009 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved
Summary
Arithmetic Operations with Signed Numbers

Using the signed number notation with negative numbers in 2s


complement form simplifies addition and subtraction of signed numbers.

Rules for addition: Add the two signed numbers. Discard any final carries. The
result is in signed form.
Examples:

00011110 = +30 00001110 = +14 11111111 = -1


00001111 = +15 11101111 = -17 11111000 = -8
00101101 = +45 11111101 = -3 1 11110111 = -9
Discard carry

Floyd, Digital Fundamentals, 10th ed 2009 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved
Summary
Arithmetic Operations with Signed Numbers

Note that if the number of bits required for the answer is exceeded,
overflow will occur. This occurs only if both numbers have the same sign.
The overflow will be indicated by an incorrect sign bit.

Two examples are:

01000000 = +128 10000001 = -127


01000001 = +129 10000001 = -127
10000001 = -126 Discard carry 100000010 = +2

Wrong! The answer is incorrect


and the sign bit has changed.

Floyd, Digital Fundamentals, 10th ed 2009 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved
Summary
Arithmetic Operations with Signed Numbers

Rules for subtraction: 2s complement the subtrahend and add the numbers.
Discard any final carries. The result is in signed form.

Repeat the examples done previously, but subtract:

00011110 (+30) 00001110 (+14) 11111111 (-1)


- 00001111 (+15) - 11101111 (-17) - 11111000 (-8)

2s complement subtrahend and add:


00011110 = +30 00001110 = +14 11111111 = -1
11110001 = -15 00010001 = +17 00001000 = +8
1 00001111 = +15 00011111 = +31 1 00000111 = +7
Discard carry Discard carry

Floyd, Digital Fundamentals, 10th ed 2009 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved
Binary Codes
Summary
Decimal Binary BCD
BCD 0 0000 0000
1 0001 0001
Binary coded decimal (BCD) is a weighted 2 0010 0010
code that is commonly used in digital systems
3 0011 0011
when it is necessary to show decimal
4 0100 0100
numbers such as in clock displays.
5 0101 0101
6 0110 0110
7 0111 0111
The table illustrates the 8 1000 1000
difference between straight binary and 9 1001 1001
BCD. BCD represents each decimal digit 10 1010 0001 0000
with a 4-bit code. Notice that the codes 11 1011 0001 0001
1010 through 1111 are not used in BCD. 12 1100 0001 0010
13 1101 0001 0011
14 1110 0001 0100
15 1111 0001 0101

Floyd, Digital Fundamentals, 10th ed 2009 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved
Summary

What is the decimal equivalent for the BCD number


1000 0011 0101 1001?

8 3 5 4

Floyd, Digital Fundamentals, 10th ed 2009 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved
Summary
BCD

A lab experiment in which BCD is


converted to decimal is shown.

Floyd, Digital Fundamentals, 10th ed 2009 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved
Summary
Decimal Binary Gray code
Gray code 0 0000 0000
1 0001 0001
Gray code is an unweighted code that has a 2 0010 0011
single bit change between one code word and
3 0011 0010
the next in a sequence. Gray code is used to
4 0100 0110
avoid problems in systems where an error can
occur if more than one bit changes at a time. 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

Floyd, Digital Fundamentals, 10th ed 2009 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved
Summary
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

Floyd, Digital Fundamentals, 10th ed 2009 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved
Decimal Binary Gray
0 0 0 0 0 0 0 0 0
1 0 0 0 1 0 0 0 1
2 0 0 1 0 0 0 1 1
3 0 0 1 1 0 0 1 0
4 0 1 0 0 0 1 1 0
5 0 1 0 1 0 1 1 1
6 0 1 1 0 0 1 0 1
7 0 1 1 1 0 1 0 0
8 1 0 0 0 1 1 0 0
9 1 0 0 1 1 1 0 1
10 1 0 1 0 1 1 1 1
11 1 0 1 1 1 1 1 0
12 1 1 0 0 1 0 1 0
13 1 1 0 1 1 0 1 1
14 1 1 1 0 1 0 0 1
15 1 1 1 1 1 0 0 0

Floyd, Digital Fundamentals, 10th ed 2009 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved
Binary-to-Gray Conversion
The MSB (Left-most) bit in both the binary and the Gray code are the same
Going from left to right, add each adjacent pair of binary code bits to get the
next Gray code bit. Discard carries
Example 1 + 0 1 1 0 Binary

1 1 1 0 1 Gray

Gray -to- Binary Conversion


The MSB (Left-most) bit in both the binary and the Gray code are the same
Going from left to right, add each binary code bit generated to the next Gray
code bit. Discard carries

Example 1 0 1 1 0
+ Gray

1 1 0 1 1
Binary
Floyd, Digital Fundamentals, 10th ed 2009 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved
Summary
ASCII

ASCII is a code for alphanumeric characters and control characters. 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.

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.

Floyd, Digital Fundamentals, 10th ed 2009 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved
Summary
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 1s 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.

Floyd, Digital Fundamentals, 10th ed 2009 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved

You might also like