Download presentation
Published byJudith McBride Modified over 9 years ago
1
CHAPTER 2 Number Systems, Operations, and Codes
Digital Fundamentals CHAPTER 2 Number Systems, Operations, and Codes
2
Decimal Numbers The decimal number system has ten digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 The decimal numbering system has a base of 10 with each position weighted by a factor of 10:
3
Binary Numbers Two digits called bits 0 or 1
Right most bit is least significant bit Left most bit is most significant bit Each position is weighted by a factor of 2. Decimal point
4
Counting in Binary Decimal Number Binary Number
5
Figure 2–1 Illustration of a simple binary counting application.
Thomas L. Floyd Digital Fundamentals, 9e Copyright ©2006 by Pearson Education, Inc. Upper Saddle River, New Jersey All rights reserved.
6
Binary Numbers The binary number system has two digits: 0 and 1
The binary numbering system has a base of 2 with each position weighted by a factor of 2:
7
Binary to Decimal Add the weights of all the bits that are 1.
Ignore the bits that are 0. Convert to decimal. 1st determine the weights = = = 109
8
Decimal-to-Binary Conversion
Sum-of-weights method Repeated division-by-2 method Conversion of decimal fractions to binary
9
Repeated Division by 2 Divide the number by 2 and write down the remainder. Continue the process until the whole-number quotient is 0. Convert decimal 19 to binary. Convert decimal 45 to binary.
10
Decimal Fractions Repeated multiplication by 2
Multiply the decimal fraction by 2 Write down the carry bit if more than 1 Continue process until you have the desired number of bits or when the fractional part is all zeros.
11
Convert to binary Carry MSB LSB X 2 = X 2 = X 2 = X 2 =
12
Binary Arithmetic Binary addition Binary subtraction
Binary multiplication Binary division
13
Complements of Binary Numbers
1’s complements 2’s complements
14
Complements of Binary Numbers
1’s complement Change all 1s to 0s and all 0s to 1s
15
Complements of Binary Numbers
2’s complement Find 1’s complement and then add 1
16
Signed Numbers
17
Topics for Signed Numbers
Signed-magnitude form 1’s and 2’s complement form Decimal value of signed numbers (How to convert) Range of values (max and min) Floating-point numbers
18
Signed Numbers Signed-magnitude form
The sign bit is the left-most bit in a signed binary number A 0 sign bit indicates a positive magnitude A 1 sign bit indicates a negative magnitude
19
Signed Numbers 1’s complement form 2’s complement form
A negative value is the 1’s complement of the corresponding positive value 2’s complement form A negative value is the 2’s complement of the corresponding positive value
20
Signed Numbers Decimal value of signed numbers Sign-magnitude
1’s complement 2’s complement
21
Signed Numbers Range of Values Total combinations = 2n
2’s complement form: – (2n – 1) to + (2n – 1 – 1) Range for 8 bit number: n = 8 -(28-1) = -27 = minimum +(28-1) – 1 = = maximum Total combination of numbers is 28 = 256.
22
Signed Numbers Range for 16 bit number: n = 16 -(216-1) = = minimum +(216-1) - 1 = +215 = maximum Total combinations is 216 = (64K) 8 bit examples: = -128 = -1 = -127 = +127
23
Signed Numbers Floating-point numbers Two Parts Three forms
Can represent very large or very small numbers based on scientific notation. Binary point “floats”. Two Parts Mantissa represents magnitude of number Exponent represents number of places that binary point is to be moved Three forms Single-precision (32 bits) float Double-precision (64 bits) double Extended-precision (80 bits) long double Also have Quadruple and Quadruple extended!
24
Single Precision IEEE 754 standard
32 bits S Exponent (E) Mantissa (fraction, F) 1 bit bits bits IEEE 754 standard Mantissa (F) has hidden bit so actually has 24 bits. Gives 7 significant figures. 1st bit in mantissa is always a one Exponent (E) is biased by 127 called Excess-127 Notation Add 127 to exponent so easier to compare Range of exponents is -126 to +128 Sign (S) bit tells whether number is negative or positive
25
Single Precision Example: Convert to Floating Point 1st, convert to binary using divide by 2 method = Positive number, so sign bit (S) equals 0. 2nd, count number of places to move binary point = x 212 Add 127 to 12 = = S E F Fill in with trailing zeroes Mantissa is fractional part, Finally, put everything together
26
Special Cases Zero and infinity are special cases Not a Number (NaN)
Can have +0 or -0 depending on sign bit Can also have +∞ or -∞ Not a Number (NaN) if underflow or overflow Type Exponent Mantissa Zeroes Denormalized numbers non zero Normalized numbers 1 to 2e − 2 any Infinities 2e − 1 NaNs
27
Examples Type Exponent Mantissa Value Zero 0000 0000
0.0 One 1.0 Denormalized number 5.9×10-39 Large normalized number 3.4×1038 Small normalized number 1.18×10-38 Infinity NaN
28
Double Precision Exponent has 11 bits so uses Excess-1023 Notation
Mantissa has 53 bits (one hidden) 53 bits gives 16 significant figures
29
Arithmetic Operations with Signed Numbers
Addition Subtraction Multiplication Division
30
Arithmetic Operations with Signed Numbers
Addition of Signed Numbers The parts of an addition function are: Augend - The first number Addend - The second number Sum The result Numbers are always added two at a time.
31
Arithmetic Operations with Signed Numbers
Four conditions for adding numbers: 1. Both numbers are positive. 2. A positive number that is larger than a negative number. 3. A negative number that is larger than a positive number. 4. Both numbers are negative.
32
Arithmetic Operations with Signed Numbers
Signs for Addition When both numbers are positive, the sum is positive. When the larger number is positive and the smaller is negative, the sum is positive. The carry is discarded.
33
Arithmetic Operations with Signed Numbers
Signs for Addition When the larger number is negative and the smaller is positive, the sum is negative (2’s complement form). When both numbers are negative, the sum is negative (2’s complement form). The carry bit is discarded.
34
Examples (8 bit numbers)
Add 7 and 4 (both positive) Add 15 and -6 (positive > negative) Add 16 and -24 (negative > positive) Add -5 and -9 (both negative) Discard carry Sign bit is negative so negative number in 2’s complement form Discard carry
35
Overflow Overflow occurs when number of bits in sum exceeds number of bits in addend or augend. Overflow is indicated by the wrong sign. Occurs only when both numbers are positive or both numbers are negative _________ ____ Sign Incorrect Magnitude Incorrect
36
Arithmetic Operations with Signed Numbers
Subtraction of Signed Numbers The parts of a subtraction function are: Minuend - The first number Subtrahend - The second number Difference - The result Subtraction is addition with the sign of the subtrahend changed.
37
Arithmetic Operations with Signed Numbers
Subtraction The sign of a positive or negative binary number is changed by taking its 2’s complement To subtract two signed numbers, take the 2’s complement of the subtrahend and add. Discard any final carry bit.
38
Subtraction Examples Find 8 minus 3. Find 12 minus -9.
Discard carry Minuend Subtrahend Difference Discard carry
39
Arithmetic Operations with Signed Numbers
Multiplication of Signed Numbers The parts of a multiplication function are: Multiplicand - First number Multiplier - Second number Product - Result Multiplication is equivalent to adding a number to itself a number of times equal to the multiplier.
40
Arithmetic Operations with Signed Numbers
There are two methods for multiplication: Direct addition add multiplicand multiple times equal to the multiplier Can take a long time if multiplier is large Partial products Similar to long hand multiplication The method of partial products is the most commonly used.
41
Arithmetic Operations with Signed Numbers
Multiplication of Signed Numbers If the signs are the same, the product is positive. (+ X + = + or - X - = +) If the signs are different, the product is negative. (+ X - = or - X + = -)
42
Multiplication Example
Both numbers must be in uncomplemented form Multiply 3 by -5. Opposite signs, so product will be negative. = = ’s complement of Multiplicand X Multiplier First partial product Second partial product Sum of 1st and 2nd Third partial product Sum and Final Product Final result is negative, so take 2’s complement is the result which in decimal is -15.
43
Arithmetic Operations with Signed Numbers
Division of Signed Numbers The parts of a division operation are: Dividend Divisor Quotient Division is equivalent to subtracting the divisor from the dividend a number of times equal to the quotient.
44
Arithmetic Operations with Signed Numbers
Division of Signed Numbers If the signs are the same, the quotient is positive. (+ ÷ + = + or - ÷ - = +) If the signs are different, the quotient is negative. (+ ÷ - = - or - ÷ + = -)
45
Division Example Both numbers must be in uncomplemented form
Divide by Both numbers are positive so quotient will be positive. Set the quotient to zero initially. quotient: Dividend ’s complement of Divisor First partial remainder Add 1 to quotient: = Subtract the divisor from the dividend by using 2’s complement addition. ( ) Ignore the carry bit. First partial remainder ’s complement of Divisor zero remainder Add 1 to quotient: = Subtract the divisor from the 1st partial remainder using 2’s complement addition. So final quotient is and final remainder is
46
Hexadecimal Numbers
47
Hexadecimal Numbers Decimal, binary, and hexadecimal numbers
4 bits is a nibble FF16 = 25510
48
Hexadecimal Numbers Binary-to-hexadecimal conversion
Hexadecimal-to-decimal conversion Decimal-to-hexadecimal conversion
49
Hexadecimal Numbers Binary-to-hexadecimal conversion
Break the binary number into 4-bit groups Replace each group with the hexadecimal equivalent Convert to Hex C A = CA5716 Convert 10A416 to binary =
50
Hexadecimal Numbers Hexadecimal-to-decimal conversion
Convert the hexadecimal to groups of 4-bit binary Convert the binary to decimal
51
Hexadecimal Numbers Decimal-to-hexadecimal conversion
Convert to binary by repeated division by 2 and then convert binary to hex Repeated division by 16
52
Figure 2–4 Getting the 2’s complement of a hexadecimal number, Method 1.
53
Figure 2–5 Getting the 2’s complement of a hexadecimal number, Method 2.
54
Octal Not used as frequently Convert binary to octal
Can group in 3 bits instead of 4 bits like Hex. Symbols range from 0 to 7 Example. Convert to octal. = Example. Convert to binary. =
55
Binary Coded Decimal (BCD)
56
Binary Coded Decimal (BCD)
Decimal and BCD digits
57
Digital Codes
58
Digital Codes Gray code ASCII code
59
Gray Code Unweighted - no weights associated to the bit positions
Only one bit change from one code word to the other. Minimizes chance of error
60
Conversion Binary to Gray code Example. Convert 10110 to Gray Code
MSB of Gray is set to the MSB of binary Going from left to right, add each adjacent pair of binary code bits. Discard carries. Example. Convert to Gray Code MSB of binary number is 1, so set the MSB of the Gray Code to 1. Binary Gray code Add adjacent pairs of binary numbers 1+0 1 1+1 0+1 1 1+0 1
61
Conversion Gray code to Binary Example. Convert 11011 to binary
MSB of binary is set to the MSB of Gray code Going from left to right, add the binary bit to the next Gray code bit. Discard carries. Example. Convert to binary MSB of Gray Code is 1, so set the MSB of the binary number to 1. Gray Code Binary + + + 1 +
62
Figure 2– A simplified illustration of how the Gray code solves the error problem in shaft position encoders.
63
American Standard Code for Information Interchange (ASCII)
ASCII code (1st 32 are control characters) 128 characters Uses 7 bits
64
ASCII code (graphic symbols 20h – 3Fh)
65
Digital Codes ASCII code (graphic symbols 40h – 5Fh)
66
Digital Codes ASCII code (graphic symbols 60h – 7Fh)
67
Digital Codes Extended ASCII code (80h – FFh)
Non-English alphabetic characters Currency symbols Greek letters Math symbols Drawing characters Bar graphing characters Shading characters
68
Error Detection and Correction Codes
69
Error Detection and Correction Codes
Parity error codes Odd parity – odd sum of 1’s Even parity – even sum of 1’s The sum includes the parity bit Parity bit can be at beginning or end of the code. Can detect single bit errors, but not 2 or more errors. Hamming error codes
70
Error Detection and Correction Codes
Parity error codes
71
Error Detection and Correction Codes
1 2 3 4 5 6 7 8 9 A B C D E F Hamming error codes Hamming code words Hex equivalent of the data bits
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.