You are on page 1of 42

Digital Systems

Principles and Applications


TWELFTH EDITION

CHAPTER 2
Number Systems
and Codes
Edited by
Jerry Bernardini

Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc.
Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
Chapter 2 Objectives

• Convert decimal, binary, hexadecimal


• advantages of the hexadecimal
• BCD and straight binary codes
• ASCII code
• Parity error detection

Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc.
Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
2-1 Binary to Decimal Conversion
• Convert binary to decimal by summing
the positions that contain a 1:

• An example with a greater number of bits:

Ronald Tocci/Neal Widmer/Gregory Moss


Copyright ©2007 by Pearson Education, Inc.
Digital Systems: Principles and Applications, 10e
Columbus, OH 43235
Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc. All rights reserved.

Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
2-1 Double-Dabble Binary to
Decimal Conversion
• Binary numbers verify the double-dabble method:

Ronald Tocci/Neal Widmer/Gregory Moss


Copyright ©2007 by Pearson Education, Inc.
Digital Systems: Principles and Applications, 10e
Columbus, OH 43235
Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc. All rights reserved.

Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
Binary-Decimal- Weight Method
2n 27 26 25 24 23 22 21 20

weight 128 64 32 16 8 4 2 1

example 1 0 1 0 1 0 1 0

1 128

1 32
1 8

1 2

sum 170

Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc.
Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
Decimal to Binary Weight Method
2n 27 26 25 24 23 22 21 20

weight 128 64 32 16 8 4 2 1 decimal

example 7510

0 1 0 0 -64

11
1 0 1 -8

-2

1 1

Result 0 1 0 0 1 0 1 1

Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc.
Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
2-2 Decimal to Binary Conversion

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.

Copyright ©2007 by Pearson Education, Inc.


Columbus, OH 43235
Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc. All rights reserved.

Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
2-3 Hexadecimal Number System

• Hexadecimal allows convenient handling of long


binary strings, using groups of 4 bits—Base 16
 16 possible symbols: 0-9 and A-F

Copyright ©2007 by Pearson Education, Inc.


Columbus, OH 43235
Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc. All rights reserved.

Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
2-3 Hexadecimal Number System

Relationships between
hexadecimal, decimal,
and binary numbers.

Copyright ©2007 by Pearson Education, Inc.


Columbus, OH 43235
Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc. All rights reserved.

Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
2-3 Hexadecimal Number System
– Hex to Decimal
• Convert from hex to decimal by
multiplying each hex digit by its
positional weight.
• In a 2nd example, the value 10 was substituted
for A and 15 substituted for F.

For practice, verify that 1BC216 is equal to 710610


Copyright ©2007 by Pearson Education, Inc.
Columbus, OH 43235
Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc. All rights reserved.

Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
2-3 Hexadecimal Number System
– Decimal to Hex
• Convert from decimal to hex by using
the repeated division method used for
decimal
to binary conversion.
• Divide the decimal number by 16
 The first remainder is the LSB—the last
is the MSB.

Copyright ©2007 by Pearson Education, Inc.


Columbus, OH 43235
Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc. All rights reserved.

Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
2-3 Hexadecimal Number System
– Decimal to Hex
• Convert 42310 to hex:

Copyright ©2007 by Pearson Education, Inc.


Columbus, OH 43235
Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc. All rights reserved.

Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
2-3 Hexadecimal Number System
– Decimal to Hex
• Convert 21410 to hex:

Copyright ©2007 by Pearson Education, Inc.


Columbus, OH 43235
Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc. All rights reserved.

Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
2-3 Hexadecimal Number System
– Hex to Binary
• Divide binary number into groups of four bits
(nibble)
• Convert nibble to hex

For practice, verify that BA616 = 1011101001102

Copyright ©2007 by Pearson Education, Inc.


Columbus, OH 43235
Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc. All rights reserved.

Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
2-3 Hexadecimal Number System
– Binary to Hex
• group bits in four starting with the LSB
 Each group is then converted to the hex
equivalent
 binary number is grouped into groups of
four bits & each is converted to its
equivalent hex digit.

For practice, verify that 101011111 2 = 15F16


Copyright ©2007 by Pearson Education, Inc.
Columbus, OH 43235
Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc. All rights reserved.

Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
2-3 Hexadecimal Number System
– Decimal to Hex to Binary
• Convert decimal 378 to a 16-bit binary
• Perform successive division by 16
• Remainder in hex is each hex value

37810 = 17A16

Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc.
Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
Binary Coded Decimal -BCD Code

• (BCD) is a widely used


• each decimal digit converted to binary
equivalent.
• The primary advantage of BCD is the
relative ease of converting to and from
decimal.

Copyright ©2007 by Pearson Education, Inc.


Columbus, OH 43235
Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc. All rights reserved.

Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
2-4 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.

• Reverse the process to convert BCD to decimal.

Copyright ©2007 by Pearson Education, Inc.


Columbus, OH 43235
Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc. All rights reserved.

Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
2-4 BCD Code

• Convert 0110100000111001 (BCD) to


its
decimal equivalent.

Divide the BCD number into four-bit


groups and convert each to decimal.

Copyright ©2007 by Pearson Education, Inc.


Columbus, OH 43235
Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc. All rights reserved.

Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
2-4 BCD Code

• Convert 0110100000111001 (BCD) to


its
decimal equivalent.

Divide the BCD number into four-bit


groups and convert each to decimal.

Copyright ©2007 by Pearson Education, Inc.


Columbus, OH 43235
Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc. All rights reserved.

Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
2-4 BCD Code

• Convert BCD 011111000001 to its


decimal equivalent.

The forbidden group represents


an error in the BCD number.

Copyright ©2007 by Pearson Education, Inc.


Columbus, OH 43235
Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc. All rights reserved.

Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
2-5 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.

Copyright ©2007 by Pearson Education, Inc.


Columbus, OH 43235
Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc. All rights reserved.

Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
2-5 The Gray Code

Binary to Gray Gray to Binary

Copyright ©2007 by Pearson Education, Inc.


Columbus, OH 43235
Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc. All rights reserved.

Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
Decimal-Binary-Hex-BCD-Gray
Decimal numbers 1 – 15 in binary, hex, BCD, Gray

Copyright ©2007 by Pearson Education, Inc.


Columbus, OH 43235
Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc. All rights reserved.

Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
2-7 The Byte, Nibble, and Word

• Most microcomputers handle and store


binary data and information in groups
of eight bits.
 8 bits = 1 byte.
• A byte can represent numerous types of
data/information.
• Binary numbers are often broken into
groups
of four bits.
Copyright ©2007 by Pearson Education, Inc.
Columbus, OH 43235
Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc. All rights reserved.

Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
Byte-Nibble-Word

 1 byte = 8 bits
 1 nibble = 4 bits
 1 word = Variable ( 8, 16, 32, 64 bits )
 Word size depends upon the digital system
• PC word size could be 32 or 64 bits

Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc.
Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
American Standard Code for Information
Interchange -ASCII

• Represents characters and functions on


a computer keyboard
 26 lowercase
 26 uppercase letters
 10 digits
 7 punctuation marks
 20 to 40 other characters.
 Seven bit code: 27 = 128 possible codes
 use: transfer information between
computers; computers & printers;

Copyright ©2007 by Pearson Education, Inc.


Columbus, OH 43235
Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc. All rights reserved.

Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
ASCII – Codes

Copyright ©2007 by Pearson Education, Inc.


Columbus, OH 43235
Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc. All rights reserved.

Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
ASCII – Codes Examples

example Keyboard “A” = 4116 = 6510


example Keyboard “a” = 6116 = 9710
Copyright ©2007 by Pearson Education, Inc.
Columbus, OH 43235
Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc. All rights reserved.

Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
Transmission Errors

• Electrical noise can cause errors during


transmission.
 (Spurious fluctuations in voltage or current present
in all electronic systems)

Noise can change one or more “1” to “0” or “0” to “1”


You want detect the errors and possibly correct the errors

Copyright ©2007 by Pearson Education, Inc.


Columbus, OH 43235
Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc. All rights reserved.

Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
Error Detection and Correction

• Digital systems should first detect


errors
• Then correct errors if possible
• Parity is a simple method of detection
errors
• Parity method requires the addition of
an extra bit to a code group

Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc.
Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
Parity Method for Error Detection

 The added bit is the parity bit


 It can be either a 0 or 1, depending on
the number of 1s in the code group
• There are two parity methods
• Even or odd
 The transmitter and receiver must
“agree” on the type of parity checking

Copyright ©2007 by Pearson Education, Inc.


Columbus, OH 43235
Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc. All rights reserved.

Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
Parity Method for Error Detection

• Even parity method—the total number


of bits in a group including the parity
bit must add up to an even number.
 The binary group 1 0 1 1 would require
the addition of a parity bit 1, making
the group 1 1 0 1 1.
1
• The parity bit may be added at either
end of a group.

Copyright ©2007 by Pearson Education, Inc.


Columbus, OH 43235
Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc. All rights reserved.

Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
2-9 Parity Method for Error
Detection
• Odd parity method—the total number
of bits in a group including the parity
bit must add up to an odd number.
 The binary group 1 1 1 1 would require
the addition of a parity bit 1, making
the group 1 1 1 1 1.
1

The parity bit becomes a part of the code word.


Adding a parity bit to the seven-bit ASCII
code produces an eight-bit code.

Copyright ©2007 by Pearson Education, Inc.


Columbus, OH 43235
Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc. All rights reserved.

Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
ASCII Transmission

• there must be a way to tell the receiver


a new character is coming.
 There is often a need to detect errors in
the transmission as well.
• The method of transfer is called
asynchronous data communication.
• An ASCII character must be “framed”
so the receiver knows where the data
begins and ends.
Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc.
Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
2-10 Applications

 The first bit must always be a start bit


(logic 0).
• ASCII code is sent LSB first and MSB
last.
 After the MSB, a parity bit is appended
to check for transmission errors.
 Transmission is ended by sending a stop
bit (logic 1).

Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc.
Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
Boolean Algebra and Common Logic

Boolean constants and variables are “1” and “0”


“1” could be 2 to 5 volts
“0” could be 0 to 0.8 volts

Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc.
Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
OR Gates

x=A+B x=1+1+1=1
x = A + B is read as “x equals A OR B

Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc.
Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
AND Gate

x=A B

expression x = A B is read as “x equals A AND B

Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc.
Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
NOT Gate

NOT gate is Inverter or Complementer


“1” input produces a “0” output
“0” input produces a “1” output

Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc.
Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
Combining Logic Gates

Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc.
Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved
Operator Precedence

If an expression contains both AND and OR operations, the


AND operations are performed first

Unless there are parentheses in the expression, in which case the


operation inside the parentheses is to be performed first.

This is the same rule that is used in ordinary algebra to determine


the order of operations

Digital Systems, Twelfth Edition Copyright © 2017, 2010, 2006 by Pearson Education, Inc.
Neal Widmer, Gregory Moss, & Ronald Tocci All Rights Reserved

You might also like