Vous êtes sur la page 1sur 96

Digital

Fundamentals
Tenth Edition

Floyd

Chapter 2

© 2008 Pearson Education


Introduction To Number
System

-Decimal Numbers
-Binary Numbers
-Octal Numbers
-Hexadecimal Numbers
Common Number Systems

Used by Used in
System Base Symbols humans? computers?
Decimal 10 0, 1, … 9 Yes No
Binary 2 0, 1 No Yes
Octal 8 0, 1, … 7 No No
Hexa- 16 0, 1, … 9, No No
decimal A, B, … F
Quantities/Counting

Hexa-
Decimal Binary Octal decimal
0 0 0 0
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
6 110 6 6
7 111 7 7
Quantities/Counting

Hexa-
Decimal Binary Octal decimal
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
Quantities/Counting

Hexa-
Decimal Binary Octal decimal
16 10000 20 10
17 10001 21 11
18 10010 22 12
19 10011 23 13
20 10100 24 14
21 10101 25 15
22 10110 26 16
Etc.
23 10111 27 17
Conversion Among Bases

• The possibilities:

Decimal Octal

Binary Hexadecimal
Quick Example

2510 = 110012 = 318 = 1916

Base
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 ten, 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 …
Decimal Numbers

Decimal numbers can be expressed as the sum of the


products of each digit times 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)


Decimal to Decimal (For Fun)

Decimal Octal

Binary Hexadecimal

Next slide…
Weight

12510 => 5 x 100 = 5


2 x 101 = 20
1 x 102 = 100
125

Base
Binary to Decimal Numbers

Decimal Octal

Binary Hexadecimal
Binary to Decimal Numbers

• Technique
• Multiply each bit by 2n, where n is the “weight” of the bit
• The weight is the position of the bit, starting from 0 on the right
• Add the results
Example
Bit “0”

1010112 => 1 x 20 = 1
1 x 21 = 2
0 x 22 = 0
1 x 23 = 8
0 x 24 = 0
1 x 25 = 32
4310
Octal to Decimal Numbers

Decimal Octal

Binary Hexadecimal
Octal to Decimal Numbers

• Technique
• Multiply each bit by 8n, where n is the “weight” of the bit
• The weight is the position of the bit, starting from 0 on the right
• Add the results
Example

7248 => 4 x 80 = 4
2 x 81 = 16
7 x 82 = 448
46810
Hexa-decimal to Decimal Numbers

Decimal Octal

Binary Hexadecimal
Hexa-decimal to Decimal Numbers

• Technique
• Multiply each bit by 16n, where n is the “weight” of the bit
• The weight is the position of the bit, starting from 0 on the right
• Add the results
Example

ABC16 => C x 160 = 12 x 1 = 12


B x 161 = 11 x 16 = 176
A x 162 = 10 x 256 = 2560
274810
Decimal to Binary Numbers

Decimal Octal

Binary Hexadecimal
Binary Numbers

For digital systems, the binary number system is used.


Binary has a radix of two and uses the digits 0 and 1 to
represent quantities.
The column weights of binary numbers are powers of
two that increase from right to left beginning with 20 =1:
…25 24 23 22 21 20.
For fractional binary numbers, the column weights
are negative powers of two that decrease from left to right:
22 21 20. 2-1 2-2 2-3 2-4 …
Decimal Binary
Number Number
Binary Numbers
0 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
Digital counters frequently have this 7 0111
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
Decimal to Binary Numbers

• Technique
• Divide by two, keep track of the remainder
• First remainder is bit 0 (LSB, least-significant bit)
• Second remainder is bit 1
• Etc.
Example
12510 = ?2 2 125
2 62 1
2 31 0
2 15 1
2 7 1
2 3 1
2 1 1
0 1

12510 = 11111012
Example

You can convert a decimal fraction to binary by repeatedly


multiplying the fractional results of successive
multiplications by 2. The carries form the binary number.
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)
Example

The decimal equivalent of a binary number can be


determined by adding the column values of all of the bits
that are 1 and discarding all of the bits that are 0.
Convert the binary number 100101.01 to decimal.
Start by writing the column weights; then add the
weights that correspond to each 1 in the number.
25 24 23 22 21 20. 2-1 2-2
32 16 8 4 2 1 . ½ ¼
1 0 0 1 0 1. 0 1
32 +4 +1 +¼ = 37¼
Octal to Binary Numbers

Decimal Octal

Binary Hexadecimal
Decimal to Binary Numbers

• Technique
• Convert each octal digit to a 3-bit equivalent binary representation
Example
7058 = ?2

7 0 5

111 000 101

7058 = 1110001012
Hexadecimal to Binary Numbers

Decimal Octal

Binary Hexadecimal
Hexadecimal to Binary Numbers

• Technique
• Convert each hexadecimal digit to a 4-bit equivalent binary representation
Example
10AF16 = ?2

1 0 A F

0001 0000 1010 1111

10AF16 = 00010000101011112
Decimal to Octal Numbers

Decimal Octal

Binary Hexadecimal
Decimal to Octal Numbers

• Technique
• Divide by 8
• Keep track of the remainder
Example
123410 = ?8

8 1234
8 154 2
8 19 2
8 2 3
0 2

123410 = 23228
Decimal to Hexadecimal Numbers

Decimal Octal

Binary Hexadecimal
Decimal to Hexadecimal Numbers

• Technique
• Divide by 16
• Keep track of the remainder
Example
123410 = ?16

16 1234
16 77 2
16 4 13 = D
0 4

123410 = 4D216
Binary to Octal Numbers

Decimal Octal

Binary Hexadecimal
Binary to Octal Numbers

• Technique
• Group bits in threes, starting on right
• Convert to octal digits
Example
10110101112 = ?8

1 011 010 111

1 3 2 7

10110101112 = 13278
Binary to Hexadecimal Numbers

Decimal Octal

Binary Hexadecimal
Binary to Hexadecimal Numbers

• Technique
• Group bits in fours, starting on right
• Convert to hexadecimal digits
Example
10101110112 = ?16

10 1011 1011

2 B B

10101110112 = 2BB16
Octal to Hexadecimal Numbers

Decimal Octal

Binary Hexadecimal
Octal to Hexadecimal Numbers

• Technique
• Use binary as an intermediary
Example
10768 = ?16

1 0 7 6

001 000 111 110

2 3 E

10768 = 23E16
Hexadecimal to Octal Numbers

Decimal Octal

Binary Hexadecimal
Hexadecimal to Octal Numbers

• Technique
• Use binary as an intermediary
Example
1F0C16 = ?8

1 F 0 C

0001 1111 0000 1100

1 7 4 1 4

1F0C16 = 174148
Exercise -----Convert……
Hexa-
Decimal Binary Octal decimal
33
1110101
703
1AF

Don’t use a calculator!

Skip answer Answer


Answers
Hexa-
Decimal Binary Octal decimal
33 100001 41 21
117 1110101 165 75
451 111000011 703 1C3
431 110101111 657 1AF
Common Powers

• Base 10
Power Preface Symbol Value
10-12 pico p .000000000001

10-9 nano n .000000001

10-6 micro  .000001

10-3 milli m .001

103 kilo k 1000

106 mega M 1000000

109 giga G 1000000000


1012 tera T 1000000000000
Common Powers

• Base 2
Power Preface Symbol Value
210 kilo k 1024

220 mega M 1048576

230 Giga G 1073741824

• What is the value of “k”, “M”, and “G”?


• In computing, particularly w.r.t. memory,
the base-2 interpretation generally applies
Multiplying Powers

• For common bases, add powers

ab  ac = ab+c

26  210 = 216 = 65,536


or…
26  210 = 64  210 = 64k
Fractions

• Decimal to decimal (just for fun)

3.14 => 4 x 10-2 = 0.04


1 x 10-1 = 0.1
3 x 100 = 3
3.14
Fractions

• Binary to decimal

10.1011 => 1 x 2-4 = 0.0625


1 x 2-3 = 0.125
0 x 2-2 = 0.0
1 x 2-1 = 0.5
0 x 20 = 0.0
1 x 21 = 2.0
2.6875
Fractions

• Decimal to binary .14579


x 2
3.14579 0.29158
x 2
0.58316
x 2
1.16632
x 2
0.33264
x 2
0.66528
x 2
1.33056
11.001001... etc.
Number System Arithmetic's
Binary Addition

• Two 1-bit values

A B A+B
0 0 0
0 1 1
1 0 1
1 1 10
“two”
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
Binary Addition

Add the binary numbers 00111 and 10101 and show


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

• Two n-bit values


• Add individual bits
• Propagate carries
• E.g.,

1 1
10101 21
+ 11001 + 25
101110 46
Multiplication (For Fun)

• Decimal

35
x 105
175
000
35
3675
Binary Multiplication

• Binary, two 1-bit values

A B AB
0 0 0
0 1 0
1 0 0
1 1 1
Binary Multiplication

• Binary, two n-bit values


• As with decimal values
• E.g.,

1110
x 1011
1110
1110
0000
1110
10011010
Binary Addition

• Two 1-bit values

A B A-B
0 0 0
1 0 1
1 1 0
10 1 1
“with a borrow of 1”
Complement Properties
Complements are used in digital computers for simplifying
subtraction operation and for logical manipulations.
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
2’s Complement

Property
Two's complement representation allows the use of binary arithmetic
operations on signed integers, yielding the correct 2's complement
results.
Positive Numbers
Positive 2's complement numbers are represented as the simple binary.
Negative Numbers
Negative 2's complement numbers are represented as the binary
number that when added to a positive number of the same magnitude
equals zero.
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 11001011 is
00110100 (1’s complement)
To form the 2’s complement, add 1: +1
1 1 0 0 1 0 1 1 00110101 (2’s complement)
1

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

0 0 1 1 0 1 0 1
Signed Binary Numbers

There are several ways to represent signed binary numbers.


In all cases, the MSB in a signed number is the sign bit, that
tells you if the number is positive or negative.
Computers use a modified 2’s complement for
signed numbers. Positive numbers are stored in true form
(with a 0 for the sign bit) and negative numbers are stored
in complement form (with a 1 for the sign bit).
For example, the positive number 58 is written using 8-bits as
00111010 (true form).

Sign bit Magnitude bits


Signed Binary Numbers

Negative numbers are written as the 2’s complement of the


corresponding positive number.
The negative number -58 is written as:
-58 = 11000110 (complement form)
Sign bit Magnitude bits
An easy way to read a signed number that uses this notation is to
assign the sign bit a column weight of -128 (for an 8-bit number).
Then add the column weights for the 1’s.
Assuming that 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
Arithmetic Operations Binary Numbers

Using the signed number notation with negative


numbers in 2’s 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
Arithmetic Operations Binary Numbers

01000000 = +128
01000001 = +129

10000001 = -127
10000001 = -127
Arithmetic Operations Binary 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.
Arithmetic Operations Binary Numbers

Rules for 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
Binary Coded Decimal (BCD) Decimal Binary BCD
0 0000 0000
1 0001 0001
Binary coded decimal (BCD) is a 2 0010 0010
weighted code that is commonly 3 0011 0011
used in digital systems when it is 4 0100 0100
5 0101 0101
necessary to show decimal 6 0110 0110
numbers such as in clock displays. 7 0111 0111
The table illustrates the 8 1000 1000
difference between straight binary and 9 1001 1001
BCD. BCD represents each decimal 10 1010 0001 0000
digit with a 4-bit code. Notice that the 11 1011 0001 0001
codes 1010 through 1111 are not used in 12 1100 0001 0010
BCD. 13 1101 0001 0011
14 1110 0001 0100
15 1111 0001 0101
Gray Code Decimal Binary Gray code
0 0000 0000
1 0001 0001
Gray code is an unweight code that 2 0010 0011
has a single bit change between one 3 0011 0010
code word and the next in a 4 0100 0110
5 0101 0111
sequence. Gray code is used to 6 0110 0101
avoid problems in systems where an 7 0111 0100
error can occur if more than one bit 8 1000 1100
changes at a time. 9 1001 1101
10 1010 1111
11 1011 1110
12 1100 1010
13 1101 1011
14 1110 1001
15 1111 1000
Gray Code

Binary sequence

Gray code sequence


Binary to Gray Code Conversion

Conversion of the Binary number 10110 to Gray code is as


follows:

MSB LSB

1+0+1+1+0 Binary Code

1 1 1 0 1 Gray Code

Discard Carry
Gray Code to Binary Conversion

Conversion of the Gray code 11011 to binary is as follows:

MSB LSB
1 1 0 1 1 Gray Code

+ + + +

1 0 0 1 0 Binary Code

Discard Carry
ASCII (American Standard Code for Information
Interchange)

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
Example 3: Determine the sequence of ASCII codes required for the
following C program statement and express them in hexadecimal:
if (y<8)

Do it yourself

Floyd, Digital Fundamentals, 10th ed © 2009 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved
ASCII (American Standard Code for Information
Interchange)

Surprize Quiz:

Q1) Determine the following ASCII coded message:

1001000 1100101 1101100 1101100 1101111 0101110


0100000 1001000 1101111 1110111 0100000 1100001
1110010 1100101 0100000 1111001 1101111 1110101
0111111

Q2) Write the message in Q1 in hexadecimal

Floyd, Digital Fundamentals, 10th ed © 2009 Pearson Education, Upper Saddle River, NJ 07458. All Rights Reserved
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).
Assign the proper even parity bit to the following code
groups:
(a) 1010 (b) 111000 (c) 101101

Make the parity bit either 1 or 0 as necessary to make the


total number of 1s even. The parity bit will be the left most
bit.
Parity Method

Assign the proper even parity bit to the following code


groups:
(a) 1010 (b) 111000 (c) 101101
(d) 1000111001001

Make the parity bit either 1 or 0 as necessary to make the


total number of 1s even. The parity bit will be the left most
bit.
(a) 01010 (b) 1111000 (c) 0101101
(d) 01000111001001
Parity Method

An odd parity system receives the following code groups:


(a) 1010 (b) 111000 (c) 101101
(d) 1000111001001
Determine which groups, if any, are in error.

Since odd parity is required, any group with an even


number of 1s is incorrect.
Except (b) all groups are in error

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

Byte A group of eight bits


Floating-point A number representation based on scientific notation
number in which the number consists of an exponent and a
mantissa(e.g. 0.14, 0.12, all fractional parts).
Hexadecimal A number system with a base of 16.
Octal A number system with a base of 8.
BCD Binary coded decimal; a digital code in which each
of the decimal digits, 0 through 9, is represented by
a group of four bits.
Binary Equivalents

-1Nibble (or nybble) = 4 bits


-1Byte = 2 nibbles = 8 bits
-1Kilobyte (KB) = 1024 bytes
-1Megabyte (MB) = 1024 kilobytes = 1,048,576 bytes
-1Gigabyte (GB) = 1024 megabytes =1,073,741,824 bytes
Key Terms

Alphanumeric Consisting of numerals, letters, and other


characters
ASCII American Standard Code for Information
Interchange; the most widely used alphanumeric
code.
Parity In relation to binary codes, the condition of
evenness or oddness in the number of 1s in a code
group.
Cyclic A type of error detection code. It is more efficient
redundancy than parity method
check (CRC)
Thank You

Vous aimerez peut-être aussi