0% found this document useful (0 votes)
3 views

ch2

Chapter 2 of 'Digital Fundamentals' by Thomas L. Floyd covers various number systems including decimal, binary, hexadecimal, and octal. It explains conversions between these systems, arithmetic operations, and representations of signed numbers and floating-point numbers. The chapter also introduces Binary Coded Decimal (BCD) and the rules for binary arithmetic operations.

Uploaded by

gxrc46r82m
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

ch2

Chapter 2 of 'Digital Fundamentals' by Thomas L. Floyd covers various number systems including decimal, binary, hexadecimal, and octal. It explains conversions between these systems, arithmetic operations, and representations of signed numbers and floating-point numbers. The chapter also introduces Binary Coded Decimal (BCD) and the rules for binary arithmetic operations.

Uploaded by

gxrc46r82m
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

Digital Fundamentals

Thomas L. Floyd

Number Systems, Operations, and Codes


Chapter 2
Ch.2 Summary

The Decimal Number System


Decimal: 10 symbols (0 through 9)
If number > 9: need more digits

Weights: powers of ten

…105 104 103 102 101 100.


For fractional: weights are negative powers of ten

… 102 101 100 . 10-1 10-2 10-3 …


Ch.2 Summary

The Decimal Number System


Decimal number: linear combination of powers
Ex) the number 9240

(9 x 103) + (2 x 102) + (4 x 101) + (0 x 100)

Ex) 480.52

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


Ch.2 Summary

The Binary Number System


Binary: 2 symbols (0 and 1)
If number > 1: need more digits

Weights: powers of two

… 25 24 23 22 21 20.

For fractional: weights are negative powers of two

… 22 21 20 . 2-1 2-2 2-3 2-4 …


Ch.2 Summary

The Binary Number


System

Notice the pattern of zeros


and ones in each column.

Digital counters frequently


have this same pattern of
digits:
Ch.2 Summary

Binary Weights

The positional weights for binary numbers are assigned as


shown below.
Ch.2 Summary

Binary-to-Decimal Conversion
Add all weights with 1 (ignoring 0)

Convert the binary number 100101.01 to decimal.

25 24 23 22 21 20. 2-1 2-2


32 16 8 4 2 1 0.5 0.25
1 0 0 1 0 1. 0 1
32 +4 +1 +0.25 = 37.25
Ch.2 Summary

Decimal-to-Binary Conversions - I
Iteratively find the maximum weight

Convert the decimal number 49 to binary.


49 is in [32, 64) : the maximum weight is 32
remainder is 49-32 = 17
17 is in [16, 32) : the maximum weight is 16
remainder is 17-16 = 1, etc…
26 25 24 23 22 21 20
64 32 16 8 4 2 1
0 1 1 0 0 0 1
Ch.2 Summary

Decimal-to-Binary Conversions - II
Iteratively dividing by 2
and get remainders.
Ch.2 Summary

Decimal-to-Binary Conversions - II
For fraction,
Iteratively multiplying by 2
and get carries.
Ch.2 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= 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
Ch.2 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.
111
10101
/ / / 21
00111 7
01110 = 14
Ch.2 Summary

Binary Multiplication
The rules for binary multiplication are:

00=0
01=0
10=0
11=1
Ch.2 Summary

Binary Division
The rules for binary division are:
(always the same with decimal operations)
Ch.2 Summary

1’s Complement
1’s complement : reversing (inverting) all the bits.

For example, the 1’s complement of 11001010


is: 00110101
We can use inverter to represent this operation
1 1 0 0 1 0 1 0

0 0 1 1 0 1 0 1
Ch.2 Summary

2’s Complement
The 2’s complement : 1’s complement + 1

Recall that the 1’s complement of 11001010 is


00110101 (1’s complement)
For 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

0 0 1 1 0 1 1 0
Ch.2 Summary

Signed Binary Numbers


MSB (most significant bit) represents the sign.
any symbol other than 0, 1 is not allowed!

Computers use a modified 2’s complement for signed numbers.


Positive numbers: sign bit = 0
Negative numbers: sign bit = 1

For example, the positive number 58 is written using 8-bits


as 00111010 (true form).

Sign bit Magnitude bits


Ch.2 Summary

Signed Binary Numbers


Negative numbers = 2’s complement of the positive number.

The number -58 is written as:


-58 = 11000110 (complement form)
Sign bit Magnitude bits
MSB is a bit with weight -128.

We have 11000110 = -58, because

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


1 1 0 0 0 1 1 0
-128 +64 +4 +2 = -58
Ch.2 Summary

Floating Point Numbers


Floating point numbers: use scientific notation.
A 32-bit single precision number:
S E (8 bits) F (23 bits)
Sign bit Biased exponent (+127) Magnitude with MSB dropped
Express the speed of light, c, in single precision floating point notation.
(c = 0.2998 x 109)
In binary, c = 0001 0001 1101 1110 1001 0101 1100 00002.
In scientific notation, c = 1.0001 1101 1110 1001 0101 1100 0000 x 228.
S = 0 because the number is positive. E = 28 + 127 = 15510 = 1001
10112. F is the next 23 bits after the first 1 is dropped.
In floating point notation, c = 0 10011011 0001 1101 1110 1001 0101 110
Ch.2 Summary

Arithmetic Operations With Signed Numbers


Use a modified 2’s complement for addition and subtraction.

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
Ch.2 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 is indicated by an incorrect sign bit.

Two examples are:

01000000 = +64 10000001 = -127


01000001 = +65 10000001 = -127
10000001= -127 Discard carry 100000010 = +2

Wrong! The answer is incorrect


and the sign bit has changed.
Ch.2 Summary

Arithmetic Operations With Signed Numbers


Rules for subtraction: use 2’s complement 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, then 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
Ch.2 Summary
Decimal Hexadecimal Binary
Hexadecimal Numbers 0 0 0000
1 1 0001
2 2 0010
Hexadecimal: 16 symbols 3 3 0011
0 through 9 and A through F. 4 4 0100
5 5 0101
6 6 0110
Large binary number can easily be 7 7 0111
converted to hexadecimal by dividing it 8 8 1000
into 4-bit groups and converting each into 9 9 1001
its equivalent hexadecimal character. 10 A 1010
11 B 1011
Express 1001 0110 0000 11102 in hexadecimal: 12 C 1100
13 D 1101
Group the binary number by 4-bits starting from
14 E 1110
the right. Thus, 1001011000001110 = 960E
15 F 1111
Ch.2 Summary
Decimal Hexadecimal Binary
Hexadecimal Numbers 0 0 0000
1 1 0001
2 2 0010
Weights: powers of 16 3 3 0011
4 4 0100
5 5 0101
6 6 0110
Column weights {4096
16 16
3
256
2 161 160
16 1
7
8
7
8
0111
1000
9 9 1001
Ex) express 1A2F16 in decimal. 10 A 1010
11 B 1011
4096 256 16 1 12 C 1100
1 A 2 F16 13 D 1101
14 E 1110
1(4096) + 10(256) +2(16) +15(1) = 670310 15 F 1111
Ch.2 Summary
Decimal Octal Binary
Octal Numbers 0 0 0000
1 1 0001
2 2 0010
Octal: 8 symbols 3 3 0011
0 through 7 4 4 0100
5 5 0101
Binary number can easily be converted to 6 6 0110
octal by grouping bits 3 at a time and 7 7 0111
writing the equivalent octal character for 8 10 1000
9 11 1001
each group.
10 12 1010
Express 1 001 011 000 001 1102 in octal: 11 13 1011
12 14 1100
Group the binary number by 3-bits starting 13 15 1101
from the right. Thus, 1001011000001110 = 14 16 1110
1130168 15 17 1111
Ch.2 Summary
Decimal Octal Binary
Octal Numbers 0 0 0000
1 1 0001
2 2 0010
Octal is also a weighted number system. 3 3 0011
The column weights are powers of 8, 4 4 0100
which increase from right to left. 5 5 0101
6 6 0110
Column weights { 83 82
512 64
81
8
80
1
7
8
7
10
0111
1000
9 11 1001
Ex) express 37028 in decimal. 10 12 1010
11 13 1011
512 64 8 1 12 14 1100
13 15 1101
3 7 0 2
14 16 1110
3(512) + 7(64) +0(8) +2(1) = 198610 15 17 1111
Ch.2 Summary

Binary Coded Decimal(BCD)


Decimal Binary BCD

Convert each decimal digits to binary number 0 0000 0000


1 0001 0001
2 0010 0010
BCD represents each decimal digit with a 4-bit 3 0011 0011
code. 4 0100 0100
5 0101 0101
Codes 1010 through 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
Ch.2 Summary

BCD
Weights of BCD: 80 40 20 10 8 4 2 1.

Example: What are the 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

Get the decimal number by adding weights:


8000 + 200 +100 + 40 + 10 + 8 +1 = 835910
Ch.2 Summary
Decimal Binary Gray code
Gray Code 0 0000 0000
1 0001 0001
2 0010 0011
3 0011 0010
Gray code is an unweighted 4 0100 0110
code 5 0101 0111
6 0110 0101
A single bit change between one 7 0111 0100
code word and the next in a 8 1000 1100
sequence. 9 1001 1101
10 1010 1111
To avoid problems in systems 11 1011 1110
where an error can occur if more 12 1100 1010
than one bit changes at a time. 13 1101 1011
14 1110 1001
15 1111 1000
Ch.2 Summary

ASCII
ASCII is a code for characters.
Originally, ASCII encoded 128 characters and symbols
using 7-bits.
Ex) 35(0100011) -> #, 97(1100001) -> a

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.
Ch.2 Summary

Parity Method for Error Detection


Method of error detection
parity bit : “extra” bit 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 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.
Ch.2 Summary

Cyclic Redundancy Check


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
checksum is generated and compared to the sent checksum. If the check
sums are the same, no error is detected.
Ch.2 Summary

Cyclic Redundancy Check

Example
11010011101100 with 1011

You might also like