You are on page 1of 72

TON DUC THANG UNIVERSITY

FACULTY OF ELECTRICAL AND ELECTRONICS


ENGINEERING

402061
DIGITAL SYSTEM DESIGN 1
CHAPTER 2: NUMBER SYSTEMS, OPERATIONS,
AND CODES

Thien T. Huynh, PhD.


1/21/2024 402061 – Chapter 2: Number Systems 1
CHAPTER 2: NUMBER SYSTEMS

 1.1 Binary Numbers


 1.2 Decimal – to – Binary Conversion
 1.3 Binary Arithmetic
 1.4 1’s and 2’s Complements of Binary
Numbers
 1.5 Signed Numbers

1/21/2024 402061 – Chapter 2: Number Systems 2


CHAPTER 2: NUMBER SYSTEM

 1.6 Arithmetic Operations with Signed


Numbers
 1.7 Hexadecimal Numbers & Octal
Numbers
 1.8 Binary Coded Decimal (BCD)
 1.9 Digital Codes, Error Detection &
Correction Codes

1/21/2024 402061 – Chapter 2: Number Systems 3


OBJECTIVES

IN THIS CHAPTER WE WILL LEARN


 Binary number system, convert between decimal
numbers and binary numbers
 Apply arithmetic operations to binary numbers
 Determine the 1’s and 2’s complements of a binary
number
 Signed binary numbers
 Implement arithmetic operations with signed
binary numbers

1/21/2024 402061 – Chapter 2: Number Systems 4


OBJECTIVES

 Convert between number systems: dec, bin, hex,


oct
 Express decimal numbers in BCD form
 Add BCD number
 Convert between the binary system and the Gray
code
 ASCII

1/21/2024 402061 – Chapter 2: Number Systems 5


CHAPTER 2: NUMBER SYSTEMS

 1.1 Binary Numbers


 1.2 Decimal – to – Binary Conversion
 1.3 Binary Arithmetic
 1.4 1’s and 2’s Complements of Binary
Numbers
 1.5 Signed Numbers

1/21/2024 402061 – Chapter 2: Number Systems 6


BINARY NUMBERS

 Decimal numbers
 The position of each digit in a weighted number system
is assigned a weight based on the base (or radix) of the
system. The radix of decimal numbers is 10, because
only ten symbols (0 through 9) are used to represent any
number.
 The column weights of decimal numbers are powers of
ten that increase from right to left beginning with 100 =1:
…105 104 103 102 101 100.
 For fractional decimal numbers, the column weights are
negative powers of ten that decrease from left to right:
102 101 100. 10-1 10-2 10-3 10-4 …

1/21/2024 402061 – Chapter 2: Number Systems 7


BINARY NUMBERS

 Decimal numbers
 Decimal numbers can be expressed as the sum of the
products of each digit multiplies with the column value
for that digit. Thus, the number 9240 can be expressed
as
(9 x 103) + (2 x 102) + (4 x 101) + (0 x 100)
or
9 x 1,000 + 2 x 100 + 4 x 10 + 0 x 1
 Express the number 480.52 as the sum of values of
each digit.

480.52 = (4 x 102) + (8 x 101) + (0 x 100) + (5 x 10-1) +(2 x 10-2)

1/21/2024 402061 – Chapter 2: Number Systems 8


BINARY NUMBERS

 Binary system
 Base 2
 2 symbols: 0 and 1

Most Significant Bit


Least Significant Bit
1/21/2024 402061 – Chapter 2: Number Systems 9
BINARY NUMBERS

1/21/2024 402061 – Chapter 2: Number Systems 10


BINARY NUMBERS

 Binary counting

Counter 0 1 0 1 0 1 0 1 0 1 Decoder

0 0 1 1 0 0 1 1 0 0

0 0 0 0 1 1 1 1 0 0

0 0 0 0 0 0 0 0 1 1

1/21/2024 402061 – Chapter 2: Number Systems 11


BINARY NUMBERS

 Convert the binary number 100101.01 to


decimal.

32 16 8 4 2 1 . ½ ¼

402061 – Chapter 2: Number


1/21/2024 12
Systems
CHAPTER 2: NUMBER SYSTEMS

 1.1 Binary Numbers


 1.2 Decimal – to – Binary Conversion
 1.3 Binary Arithmetic
 1.4 1’s and 2’s Complements of Binary
Numbers
 1.5 Signed Numbers

1/21/2024 402061 – Chapter 2: Number Systems 13


DECIMAL TO BINARY CONVERSION

 For a decimal number: repeatedly dividing by the


base

49 DEC  ? BIN

 For a decimal fraction: repeatedly multiplying by 2

0.188DEC  ? BIN

1/21/2024 402061 – Chapter 2: Number Systems 14


CHAPTER 2: NUMBER SYSTEMS

 1.1 Binary Numbers


 1.2 Decimal – to – Binary Conversion
 1.3 Binary Arithmetic
 1.4 1’s and 2’s Complements of Binary
Numbers
 1.5 Signed Numbers

1/21/2024 402061 – Chapter 2: Number Systems 15


BINARY ARITHMETIC

 Binary addition
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

1/21/2024 402061 – Chapter 2: Number Systems 16


BINARY ARITHMETIC

 Binary subtraction:
0-0=0
1-0=1
1-1=0
10 - 1 = 1 with a borrow of 1

1/21/2024 402061 – Chapter 2: Number Systems 17


BINARY ARITHMETIC

 Binary multiplication
 Binary division

1/21/2024 402061 – Chapter 2: Number Systems 18


CHAPTER 2: NUMBER SYSTEMS

 1.1 Binary Numbers


 1.2 Decimal – to – Binary Conversion
 1.3 Binary Arithmetic
 1.4 1’s and 2’s Complements of Binary
Numbers
 1.5 Signed Numbers

1/21/2024 402061 – Chapter 2: Number Systems 19


1’S AND 2’S COMPLEMENTS OF
BINARY NUMBERS

 1’s complement
 1’s complement of a binary number is 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/21/2024 402061 – Chapter 2: Number Systems 20


1’S AND 2’S COMPLEMENTS OF
BINARY NUMBERS

 2’s complement
 2’s complement = 1’s complement + 1
 The 2’s complement of 11001010 is
Digital circuit:

1/21/2024 402061 – Chapter 2: Number Systems 21


CHAPTER 2: NUMBER SYSTEMS

 1.1 Binary Numbers


 1.2 Decimal – to – Binary Conversion
 1.3 Binary Arithmetic
 1.4 1’s and 2’s Complements of Binary
Numbers
 1.5 Signed Numbers

1/21/2024 402061 – Chapter 2: Number Systems 22


SIGNED NUMBERS

 MSB is the sign bit


 MSB = 0: positive number
 MSB = 1: negative number
 For example, the positive number 58 is
written using 8-bits as 00111010 (true form).
Sign bit Magnitude bits

1/21/2024 402061 – Chapter 2: Number Systems 23


SIGNED NUMBERS

 Negative numbers are written as the 2’s


complement of the corresponding positive
number.
 The negative number -5 is written as:

5  ? BIN

1/21/2024 402061 – Chapter 2: Number Systems 24


SIGNED NUMBERS

 The negative number -58 is written as:

58 = 0111010
1000101 (1’s complement form)
-58 = 1000110 (2’s complement form)
Sign bit Magnitude bits

1/21/2024 402061 – Chapter 2: Number Systems 25


SIGNED NUMBERS

 For signed number, the weight of MSB is


always negative
 The sign bit = 128, show that 11000110 =
58 as a 2’s complement signed number:

Column weights: -128 64 32 16 8 4 2 1.


1 1 0 0 0 1 1 0
-128 +64 +4 +2 = -58

1/21/2024 402061 – Chapter 2: Number Systems 26


CHAPTER 2: NUMBER SYSTEM

 1.6 Arithmetic Operations with


Signed Numbers
 1.7 Hexadecimal Numbers & Octal
Numbers
 1.8 Binary Coded Decimal (BCD)
 1.9 Digital Codes, Error Detection &
Correction Codes

1/21/2024 402061 – Chapter 2: Number Systems 27


ARITHMETIC OPERATIONS WITH
SIGNED NUMBERS

 Addition: discard any final carries (the


result is already in signed form)

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


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

Discard
carry

1/21/2024 402061 – Chapter 2: Number Systems 28


ARITHMETIC OPERATIONS WITH
SIGNED NUMBERS

 Addition:
00000111 = +7 00001111 = +15
00000100 = +4 11111010 = -6

00010000 = +16 11111011 = -5


11101000 = -24 11110111 = -9

1/21/2024 402061 – Chapter 2: Number Systems 29


ARITHMETIC OPERATIONS WITH
SIGNED NUMBERS

 Addition:
00000111 = +7 00001111 = +15
00000100 = +4 11111010 = -6
00001011 = +11 100001001 = +9
Discard
carry

00010000 = +16 11111011 = -5


11101000 = -24 11110111 = -9
11111000 = -8 111110010 = -14
1/21/2024 402061 – Chapter 2: Number Systems 30
ARITHMETIC OPERATIONS WITH
SIGNED NUMBERS

 Overflow: occurs when numbers of bit for


the answer exceed.
 Only happen when adding numbers with the
same sign.
 The overflow will be indicated by the change of
the sign bit.
01000000 = +64 129 10000001 = -127
-254
01000001 = +65 10000001 = -127
10000001 = -127 Discard 1 00000010 = +2
carry

1/21/2024 402061 – Chapter 2: Number Systems 31


ARITHMETIC OPERATIONS WITH
SIGNED NUMBERS

 Subtraction: 2’s 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)

 2’s 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
1/21/2024 402061 – Chapter 2: Number Systems 32
CHAPTER 2: NUMBER SYSTEM

 1.6 Arithmetic Operations with Signed


Numbers
 1.7 Hexadecimal Numbers & Octal
Numbers
 1.8 Binary Coded Decimal (BCD)
 1.9 Digital Codes, Error Detection &
Correction Codes

1/21/2024 402061 – Chapter 2: Number Systems 33


HEXADECIMAL & OCTAL NUMBERS
Decimal Hexadecimal Binary

 Hexadecimal numbers 0
1
0
1
0000
0001
 Hex uses 16 characters to 2 2 0010
represent numbers 3 3 0011
4 4 0100
 Base: 16 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
1/21/2024 402061 – Chapter 2: Number Systems 34
HEXADECIMAL & OCTAL NUMBERS

 Convert from binary number: group 4 bits

 Convert to decimal
number:  Convert to decimal
number:
1A2 F  ? DEC 1 A 2 F

Remainder
1 10 2 15

0 1 26 418 6703 16

Quotient
1/21/2024 402061 – Chapter 2: Number Systems 35
HEXADECIMAL & OCTAL NUMBERS

 Convert from bin to hex


a) 1100101001010111
b) 111111000101101001
c) 1001111011110011100
 Convert from hex to bin
a) 10A416
b) CF8E16  Convert from hex to dec
c) 974216 (a) 1C16
(b) A8516
(c) 6BD16

1/21/2024 402061 – Chapter 2: Number Systems 36


HEXADECIMAL & OCTAL NUMBERS
Decimal Octal Binary

 Octal numbers 0
1
0
1
0000
0001
 Use 8 characters (0-7) to 2 2 0010
represent numbers 3 3 0011
4 4 0100
 Base: 8 5 5 0101
6 6 0110
7 7 0111
8 10 1000
9 11 1001
10 12 1010
11 13 1011
12 14 1100
13 15 1101
14 16 1110
15 17 1111
1/21/2024 402061 – Chapter 2: Number Systems 37
HEXADECIMAL & OCTAL NUMBERS

 Convert from binary number: group 3 bits

 Convert to decimal
number:  Convert to oct number:
1356OCT  ? DEC
Remainder
1 3 5 6

0 1 11 93 750 8

Quotient

1/21/2024 402061 – Chapter 2: Number Systems 38


HEXADECIMAL & OCTAL NUMBERS

 Convert from oct to bin


(a) 138
(b) 258
(c) 1408
(d) 75268
 Convert from bin to oct
(a) 110101
(b) 101111001
(c) 100110011010

1/21/2024 402061 – Chapter 2: Number Systems 39


CHAPTER 2: NUMBER SYSTEM

 1.6 Arithmetic Operations with Signed


Numbers
 1.7 Hexadecimal Numbers & Octal
Numbers
 1.8 Binary Coded Decimal (BCD)
 1.9 Digital Codes, Error Detection &
Correction Codes

1/21/2024 402061 – Chapter 2: Number Systems 40


BINARY CODE DECIMAL (BCD)

 Use 4 bits to represent


decimal numbers (09) Decimal Binary BCD
0 0000 0000
 BCD is commonly used in 1 0001 0001
digital system 2 0010 0010
3 0011 0011
 Applications: digital clocks, 4 0100 0100
5 0101 0101
digital thermometers, and 6 0110 0110
other devices with 7- 7 0111 0111
8 1000 1000
segment displays 9 1001 1001

1/21/2024 402061 – Chapter 2: Number Systems 41


BINARY CODE DECIMAL (BCD)

 BCD in terms of column weights in groups of four


bits. For an 8-bit BCD number, the column weights
are: 80 40 20 10 8 4 2 1.
What are the column weights for the BCD number
1000 0011 0101 1001?

8000 4000 2000 1000 800 400 200 100 80 40 20 10 8 4 2 1

Could add the column weights where there is a 1 to obtain


the decimal number. For this case:

8000 + 200 + 100 + 40 + 10 + 8 + 1 = 835910

1/21/2024 402061 – Chapter 2: Number Systems 42


BINARY CODE DECIMAL (BCD)

 Convert each of the following decimal numbers to


BCD:
(a) 35
(b) 98
(c) 170
(d) 2469

1/21/2024 402061 – Chapter 2: Number Systems 43


BINARY CODE DECIMAL (BCD)

 BCD addition
 Step 1: Add 2 BCD numbers,
using rules for binary
addition
 Step 2: If the result is less
than 9  valid BCD
 Step 3: If the result is more
than 9 or if a carry out of the
4-bit group is generated 
invalid BCD
=> Add 6 (0110) to the
result to get valid BCD

1/21/2024 402061 – Chapter 2: Number Systems 44


BINARY CODE DECIMAL (BCD)

 BCD addition
 More example:

1/21/2024 402061 – Chapter 2: Number Systems 45


BINARY CODE DECIMAL (BCD)

 BCD addition
16
15

1/21/2024 402061 – Chapter 2: Number Systems 46


BINARY CODE DECIMAL (BCD)

 BCD addition

67
53

1/21/2024 402061 – Chapter 2: Number Systems 47


CHAPTER 2: NUMBER SYSTEM

 1.6 Arithmetic Operations with Signed


Numbers
 1.7 Hexadecimal Numbers & Octal
Numbers
 1.8 Binary Coded Decimal (BCD)
 1.9 Digital Codes, Error Detection &
Correction Codes

1/21/2024 402061 – Chapter 2: Number Systems 48


DIGITAL CODES, ERROR DETECTION
& CORRECTION CODES

ASSIGNMENT: Find out about the following


information:
 The Gray Code
 The advantage of the Gray Code
 Convert between Gray Code and binary
 ASCII vs. Unicode
 Error detection codes
 Parity method
 Cyclic redundancy check

1/21/2024 402061 – Chapter 2: Number Systems 49


DIGITAL CODES, ERROR DETECTION
& CORRECTION CODES
Decimal Binary Gray code

 Gray code 0
1
0000
0001
0000
0001
 Is an unweighted code that 2 0010 0011
has a single bit change 3 0011 0010
4 0100 0110
between one code word and 5 0101 0111
the next in a sequence. 6 0110 0101
 Gray code is used to avoid 7 0111 0100
8 1000 1100
problems in systems where 9 1001 1101
an error can occur if more 10 1010 1111
than one bit changes at a 11 1011 1110
time. 12 1100 1010
13 1101 1011
14 1110 1001
15 1111 1000
1/21/2024 402061 – Chapter 2: Number Systems 50
DIGITAL CODES, ERROR DETECTION
& CORRECTION CODES

 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.

1/21/2024 402061 – Chapter 2: Number Systems 51


DIGITAL CODES, ERROR DETECTION
& CORRECTION CODES

 Gray code

Gray code sequence


Binary sequence

1/21/2024 402061 – Chapter 2: Number Systems 52


DIGITAL CODES, ERROR DETECTION
& CORRECTION CODES

 Gray code

402061 – Chapter 2: Number


1/21/2024 53
Systems
DIGITAL CODES, ERROR DETECTION
& CORRECTION CODES

 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.

1/21/2024 402061 – Chapter 2: Number Systems 54


DIGITAL CODES, ERROR DETECTION
& CORRECTION CODES

 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.

1/21/2024 402061 – Chapter 2: Number Systems 55


DIGITAL CODES, ERROR DETECTION
& CORRECTION CODES

 Error detection codes


 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).

1/21/2024 402061 – Chapter 2: Number Systems 56


DIGITAL CODES, ERROR DETECTION
& CORRECTION CODES

 Error detection codes


 The parity method:

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.

1/21/2024 402061 – Chapter 2: Number Systems 57


DIGITAL CODES, ERROR DETECTION
& CORRECTION CODES

 Error detection codes


 The cyclic redundancy check (CRC) is an error
detection method that can detect multiple errors
in larger blocks of data.
 At the sending end, a checksum is appended to
a block of data. At the receiving end, the check
sum is generated and compared to the sent
checksum.
 If the check sums are the same, no error is
detected.

1/21/2024 402061 – Chapter 2: Number Systems 58


DIGITAL CODES, ERROR DETECTION
& CORRECTION CODES

 Error detection codes


 The cyclic redundancy check (CRC)

1/21/2024 402061 – Chapter 2: Number Systems 59


SUMMARY

 In this chapter, we have learned:


how to count in different number systems,
convert between number systems: DEC, BIN,
HEX, OCT
arithmetic operations to binary numbers
the 1’s and 2’s complements of a binary number
signed binary numbers and their arithmetic
operations

402061 – Chapter 2: Number


1/21/2024 60
Systems
Homework #2

 Prob:
 Self-test 1->15
 Problems: section 2-1 (1, 2); section 2-2 (5, 6),
section 2-3 (11, 12), section 2-4 (15, 16), section
2-5 (19, 20), section 2-6 (21, 22), section 2-7
(29, 30), section 2-8 (35, 36), section 2-9 (41,
42), section 2-10 (45, 47),
 Prepare chap 3: logic gates

1/21/2024 402061 – Chapter 2: Number Systems 61


Quiz

1. For the binary number 1000, the weight of


the column with the 1 is
a. 4
b. 6
c. 8
d. 10

1/21/2024 402061 – Chapter 2: Number Systems 62


Quiz

2. The 2’s complement of 1000 is


a. 0111
b. 1000
c. 1001
d. 1010

1/21/2024 402061 – Chapter 2: Number Systems 63


Quiz

3. The fractional binary number 0.11 has a


decimal value of
a. ¼
b. ½
c. ¾
d. none of the above

1/21/2024 402061 – Chapter 2: Number Systems 64


Quiz

4. The hexadecimal number 2C has a decimal


equivalent value of
a. 14
b. 44
c. 64
d. none of the above

1/21/2024 402061 – Chapter 2: Number Systems 65


Quiz

5. Assume that a floating point number is


represented in binary. If the sign bit is 1, the
a. number is negative
b. number is positive
c. exponent is negative
d. exponent is positive

1/21/2024 402061 – Chapter 2: Number Systems 66


Quiz

6. When two positive signed numbers are


added, the result may be larger that the size of
the original numbers, creating overflow. This
condition is indicated by
a. a change in the sign bit
b. a carry out of the sign position
c. a zero result
d. smoke
1/21/2024 402061 – Chapter 2: Number Systems 67
Quiz

7. The number 1010 in BCD is


a. equal to decimal eight
b. equal to decimal ten
c. equal to decimal twelve
d. invalid

1/21/2024 402061 – Chapter 2: Number Systems 68


Quiz

8. An example of an unweighted code is


a. binary
b. decimal
c. BCD
d. Gray code

1/21/2024 402061 – Chapter 2: Number Systems 69


Quiz

9. An example of an alphanumeric code is


a. hexadecimal
b. ASCII
c. BCD
d. CRC

1/21/2024 402061 – Chapter 2: Number Systems 70


Quiz

10. An example of an error detection method


for transmitted data is the
a. parity check
b. CRC
c. both of the above
d. none of the above

1/21/2024 402061 – Chapter 2: Number Systems 71


Quiz

Answers:
1. c 6. a
2. b 7. d
3. c 8. d
4. b 9. b
5. a 10. c

1/21/2024 402061 – Chapter 2: Number Systems 72

You might also like