positional number system - lsu chapter 2.pdf · positional number system ... –decimal. –binary....
TRANSCRIPT
Positional Number System
• A number is represented by a string of digits where each digit position has an associated weight.
• The weight is based on the radix of the number system.
• Some common radices:– Decimal.– Binary.– Octal.– Hexadecimal.
Notation
• Decimal.– W = 12310 = 123d = 123
• Binary.– X = 102 = 10b
• Octal.– Y = 458 = 45q = 45o
• Hexadecimal.– Z = 0A316 = 0A3h = 0xA3
Radix 10 Numbers• Decimal.
– Here the base or radix is 10.• Digits used.
– 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9.
2 1 0
217200 10 72 10 1 10 7 10
DDD
== + +
= × + × + ×
Radix 2 Numbers
• Binary.– Here the base or radix is 2.
• Digits used:– 0, and 1.
5.521212021
1.1011012
2
=×+×+×+×=
=−
BBB
Radix 8 Numbers• Octal.
– Here the base or radix is 8.• Digits used:
– 0,1,2,3,4,5,6, and 7.
625.26858283
5.32101
8
=×+×+×=
=−
OOO
Radix 16 Numbers
• Hexadecimal.– Here the base or radix is 16.
• Digits used:– 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C,
D, E, and F.
161 0 1
1 0 1
3 .8
3 16 16 8 163 16 12 16 8 1660.5
H CH CHH
−
−
=
= × + × + ×
= × + × + ×=
Radix r Numbers1 0 1
1 0 11 0 1
.n mn m
n m
ni
ii m
A a a a a aA a r a r a r a r a r
A a r
− −
− −− −
=−
=
= + + + + + +
= ∑
K K
K K
Conversion Table
F17111115E16111014D15110113C14110012B13101111A121010109111001981010008771117661106551015441004331132210211110000
HexadecimalOctalBinaryDecimal
Binary to Octal, Octal to Binary Conversions
• Substitute a three binary digit string with an octal digit.
28
82
1001011117544.111.0011
==
Binary to Hexadecimal, Hexadecimal to Binary
Conversions
• Substitute a four binary digit string, called a nibble, with a hexadecimal digit.
16 2
2 16
8A.C 1000 1010. 111 1110 1011 =1EB
=
Simple Conversions
• The conversions just described are simple due to the fact that the radices are all powers of two.– 21 = binary.– 8 = 23 = octal.– 16 = 24 = hexadecimal.
Radix r to Decimal Conversions
ni
ii m
n mn m
A a r
A a r a r= −
−−
=
= + +
∑K
• Ex:– 1012 = 1X22 + 0X21 + 1X20 = 5– 4325 = 4X52 + 3X51 + 2X50 = 117– 758 = 7X81 + 5X80 = 61– 1A16 = 1X161 + 10X160 = 26
Decimal to Radix r Conversions
1 0 11 0 1
1 01 0
11
Integral part
Fractional part
ni
ii m
n n mn n m
I F
n nI n n
mF m
A a r
A a r a r a r a r a rA A A
A a r a r a r
A a r a r
=−
− − −− − −
−−
− −− −
=
= + + + + + += +
= + + +
= + +
∑K K
K
K
Decimal to Radix r Conversions
1 1 01 1 0
1 1 0
Integral part
(( ) )
n nI n n
I n n
A a r a r a r a rA a r a r a r a
−−
−
= + + + += + + + +
K
K
• AI / r = (anr+ an-1)r+…+ a1 as the quotient and a0 as the remainder.
• Divide the result repeatedly until a zero quotients is reached.
• The remainders of the consecutive divisions form the numbers in base r.
Decimal to Radix r Conversions
• Convert 26 decimal to binary.– Quotient Remainder– 26/2 13 0 LSB– 13/2 6 1– 6/2 3 0– 3/2 1 1– 1/2 0 1 MSB
• 26 = 110102
Decimal to Radix r Conversions
( )( )( )mF
mmF
arararArararaA
−−
−−
−−
−−
−−
−−
+++=
+++=1
21
11
22
11
Part Fractional
K
K
• AF * r = r -1(a-1+ r –1 (a-2 +…)) * r= a-1 + r –1 (a-2 +…)
• Multiplying the fractional part by r results in a mixed number.
• The integral part of this mixed number is the conversion’s required digit.
Decimal to Radix r Conversions
• This algorithm is not guaranteed to terminate, since a finite fraction in one number system may correspond to an infinite one in another number system.
Decimal to Radix r Conversions
• Convert 0.75 decimal to binary.
Mixed no. Integral part– 0.75 X 2 1.5 1 MSB– 0.5 X 2 1.0 1 LSB
• 0.75 = 0.112
Decimal to Radix r Conversions
• Convert 46.375 to binary.
2101110.011 46.375
LSB11.020.511.520.75
MSB00.7520.375:partFractional
MSB102/1012/2125/21511/211123/2
LSB02346/2:part Integral
=
=×=×=×
======
Decimal to Radix r Conversions
• Convert 465.56 to octal.
8721.446 465.5625
LSB66.7280.84384.380.48
MSB44.4880.56:partFractional
MSD707/82758/8
LSD158465/8:part Integral
=
=×=×=×
===
Binary Addition Table
Carry in X Y Sum Carry out0 0 0 0 00 0 1 1 00 1 0 1 00 1 1 0 11 0 0 1 01 0 1 0 11 1 0 0 11 1 1 1 1
Binary Subtraction Table
Borrow in X Y Difference Borrow out0 0 0 0 00 0 1 1 10 1 0 1 00 1 1 0 01 0 0 1 11 0 1 0 11 1 0 0 01 1 1 1 1
Negative Number Representation
• Signed magnitude.• Complement number system:
– Radix-complement.– Diminished radix-complement.
• Excess representation.
Signed Magnitude Representation
021 aaaA nn K−−=
• A is a n digit number, where an-1 is the sign, and the remaining n–1 bits are the magnitude.
• an-1– Positive if equal to 0.– Negative if equal to 1 or r-1 for r
greater than 2.
• Range is – (2n-1 - 1) to (2n-1 - 1).• Two zero representations:
– 00…02 = +0– 10…02 = -0
Addition and Subtraction
• Check sign.– If equal.
• Add magnitudes and give the result the same sign.
– If different.• Compare magnitudes.• Subtract the smaller from the
larger and give the result the sign of the larger.
Complement Representation
• Negation is accomplished by taking the complement of the numbers.
• Two numbers in complement representation may be added or subtracted directly without sign and magnitude checks.
• Numbers in complement representation may be sign extended.
Diminished Radix Complement
• Also known as:– One’s complement (r = 2).– Nine’s complement (r = 10).
• 1’s Complement of A = (2n - 1) – A– n is the numbers of digits in A.
2
22
222
28
2
000111011110001011111111
11100010)1100000000(11100010)12(
of Complement
11100010for ,of complementtheCompute :Example
=−=
−−=−−=
=
=
BBBB
AB
AA
Diminished Radix Complement
• The easy way to get the one’s complement of a binary number is by complementing each individual digit of that number.
• Ex:– A = 111000102
– B = One’s complement of A– B = 000111012
Diminished Radix Complement
• Range is – (2n-1 - 1) to (2n-1 - 1).• Two zero representations:
– 00…02 = +0– 11…12 = -0
Radix Complement• Also known as:
– Two’s complement (r = 2).– Ten’s complement (r = 10).
• 2’s Complement of A = 2n – A– n is the numbers of digits in A.
• B = 2’s Complement of A = 2n – A• B = 2n – A –1 + 1• B = (2n – 1 – A) + 1• Ex:
– A = 111000102
– B = Two’s complement of A– B = 000111012 + 12
– B = 000111102
Radix Complement• The easy way to get the two’s
complement of a binary number is to search that number starting with the LSB until you find the rightmost one digit. Leave that digit and all other digits to the right of it unchanged. Complement all digits to the left of that one digit.
• Ex:– A = 111010002– B = Two’s complement of A– B = 000110002
Radix Complement
• Range is – 2n-1 to 2n-1 - 1.• One zero representation:
– 00…02 = 0
Excess Representation• ED is an unsigned integer,
represented by a n-bit string, such that 0 ≤ ED < 2n.
• EB represents the signed integer ED - B, where B is the bias of the number system.
ED EB Excess-3 Excess-40 000 -3 -41 001 -2 -32 010 -1 -23 011 0 -14 100 1 05 101 2 16 110 3 27 111 4 3
Negative Number Representation
Two's One's Signed ExcessDecimal Complement Complement Magnitude 2m-1
-8 1000 0000-7 1001 1000 1111 0001-6 1010 1001 1110 0010-5 1011 1010 1101 0011-4 1100 1011 1100 0100-3 1101 1100 1011 0101-2 1110 1101 1010 0110-1 1111 1110 1001 01110 0000 1111 or 0000 1000 or 0000 10001 0001 0001 0001 10012 0010 0010 0010 10103 0011 0011 0011 10114 0100 0100 0100 11005 0101 0101 0101 11016 0110 0110 0110 11107 0111 0111 0111 1111
Two’s Complement Addition
• Simply add the numbers ignoring any carries beyond the MSB.
• The result will always be correct as long as the range of the number system is not exceeded.
• Example:
001130111701015010151110200102
++++−
Overflow• Overflow occurs when the
result of an addition exceeds the range of the number system.
• So, will overflow occur when numbers with different signs are added?
• Detection of an overflow:– Compare the carries into and out of
the sign bit, if they are different an overflow has occurred.
– The sign of the addends are the same and they differ from the sums sign.
– Ex:• - 4 + ( -5 ) = -9• 4 + 5 = 9
Overflow
011191001910115010151100401004
−++−++
−
Two’s Complement Subtraction
• Subtraction is performed by negating the subtrahend by taking its two’s complement, then adding it to the minuend using normal two’s complement addition rules.
• Ex:
001000102111000102010001004
+−−
Graphical View0000
1000
0001
0010
0011
01011011
1100
1101
1110
1111
01101010
01111001
0100
+0
–8
+1–1
+7–7
+2–2
+3–3
+4–4
+5–5
+6–6
Subtraction ofpositive numbers
Addition ofpositive numbers
0000
1000
0001
0010
0011
01011011
1100
1101
1110
1111
01101010
01111001
0100
0
8
115
79
214
313
412
511
610
Subtraction Addition
Copyright © 2000 by Prentice Hall, Inc.Digital Design Principles and Practices, 3/e
One’s Complement Addition
• Perform addition; If there is a carry out of the sign bit, add one to the result.
• This is called the end-around carry.
• Ex:• - 3 + ( -4 ) = -7
One’s Complement Subtraction
• Subtraction is performed by negating the subtrahend by taking its one’s complement, then adding it to the minuend using normal one’s complement addition rules.
• Ex:• - 3 – ( -4 ) = 1
Multiplication
• Performed just like you would performed it in decimal, except the additions are in binary.
• Ex:• 11 X 13= 143
• Signed (2’s comp.) multiplication can be performed by the addition of shifted multiplicands, except for the last multiplicand which should be negated then shifted.
• Ex:• -3 X –5 = 15
Division• Use the shift and subtract
method you learned in grammar school.
• Ex:• 217 / 11 = 19 with 8 remaining• 217 = 110110012
• Signed division can be performed by dividing the numbers as unsigned numbers then given them a “+” sign if the operands have the same sign and “–” if the operands have different signs.
Binary Codes For Decimal Numbers
Decimal BCDDigit 8421 2421 Excess-3 Biquinary 1-out-of-10
0 0000 0000 0011 0100001 10000000001 0001 0001 0100 0100010 01000000002 0010 0010 0101 0100100 00100000003 0011 0011 0110 0101000 00010000004 0100 0100 0111 0110000 00001000005 0101 1011 1000 1000001 00000100006 0110 1100 1001 1000010 00000010007 0111 1101 1010 1000100 00000001008 1000 1110 1011 1001000 00000000109 1001 1111 1100 1010000 0000000001
1010 0101 0000 0000000 00000000001011 0110 0001 0000001 00000000111100 0111 0010 0000010 00000001011101 1000 1101 0000011 00000001101110 1001 1110 0000101 00000001111111 1010 1111 … …
Unused codes words
Binary Coded Decimal
• Also known as BCD or 8421 weighted code.
• BCD encodes the decimal digits 0 – 9 with their unsigned binary representation, 00002 – 10012.
• Packed BCD – a byte represents two BCD numbers.
• Unpacked BCD - a byte represents only one BCD number.
BCD Addition
• Similar to unsigned binary addition, except that a correction is required should the result exceed 10012.
• The correct result may be obtained by adding 01102.
• Ex:• 6 + 8 = 14• 3 + 3 = 6• 9 + 9 = 18
Self Complementing Codes
• A code that the 9’s complement of their decimal representation may be obtained by simply complementing the individual bits of the code word.– 2421.– Excess-3.
• Ex:– Decimal 2421 Excess-3– 6 11002 10012
– 9-6=3 00112 01102
Code Representations With More Than 4 Bits
• Biquinary.– XXYYYYY
• XX– 01 = Numbers 0-4– 10 = Numbers 5-9
• YYYYY– Indicates which of the five numbers
from the above ranges is represented.
• Advantages.– Easier to detect errors.
Gray Code• The codes were patented in
1953 by Frank Gray, a Bell Labs researcher.
• A binary sequence with the property that only one bit changes between any two consecutive elements.
• Used in electromechanical applications of digital systems, like copiers, brake systems, machine tools, etc.
Gray Code000111
001
011100
010
110
101
0 0 1
000100
001
010110
011
101
111
0 0 1
Copyright © 2000 by Prentice Hall, Inc.Digital Design Principles and Practices, 3/e
Gray Code
• How to construct a Gray code.– 1st Method - Reflected Code.
• A one bit Gray code has two words, 0 and 1.
• The first 2n code words of a n + 1 bit Gray code equal the code words of the n bit Gray code written in order with a leading 0 appended.
• The last 2n code words of a n + 1 bit Gray code equal the code words of the n bit Gray code written in reverse order with a leading 1 appended.
Gray Code
– 2nd Method – Direct derivation from corresponding binary representation.
• The bits of a n bit binary or Gray codes are numbered from right to left as 0 to n-1.
• Bit i of a Gray code word is 0 if bits i and i + 1 of the corresponding binary code are the same, else bit i is 1. When i + 1 = n then bit n of the binary code word is considered to be 0.
Character Codes
• ASCII – American Standard Code for Information Interchange.– Control (0x0 – 0x20).– Alphabet and alphanumeric
characters (0x21 – 0x7f).– Special characters (0x80 – 0xff).
• EBCDIC.– IBM.
• Baudot.– TDDs – telecommunication
devices for the deaf.– HAM radio applications.
ASCII Table
0H 1H 2H 3H 4H 5H 6H 7H0H NUL DLE SP 0 @ P ` p1H SOH DC1 ! 1 A Q a q2H STX DC2 " 2 B R b r3H ETX DC3 # 3 C S c s4H EOT DC4 $ 4 D T d t5H ENQ NAK % 5 E U e u6H ACK SYN & 6 F V f v7H BEL ETB ' 7 G W g w8H BS CAN ( 8 H X h x9H HT EM ) 9 I Y I y
0AH LF SUB * : J Z j z0BH VT ESC + ; K [ k {0CH FF FS , < L \ l |0DH CR GS - = M ] m }0EH SO RS . > N ^ n ~0FH SI US / ? O _ o DEL
Codes For Actions, Conditions, and States
• For n actions, conditions, and/or states, a code with b bits, whereb = log2 n , may be used.
CodeState Green Yellow Red Green Yellow Red Word
N-S Go ON off off off off ON 000N-S Wait off ON off off off ON 001N-S Delay off off ON off off 0 010E-W Go off off ON ON off off 100E-W Wait off off ON off ON off 101E-W Delay off off ON off off ON 110
LigthsN-S E-W
Codes For Actions, Conditions, and States
deviceID
compare
deviceenable
Device
deviceID
compare
deviceenable
Device
deviceID
compare
deviceenable
Device
binary-coded device select
deviceenable
Device
deviceenable
Device
deviceenable
Device
ControlUnit
(a)
(b)
1-out-of-n coded device select
ControlUnit
Copyright © 2000 by Prentice Hall, Inc.Digital Design Principles and Practices, 3/e
n-Cubes And Distance• An n-cube has 2n vertices.• Each vertex is labeled with
an n bit string.• n-cubes makes it easy to
visualize certain coding and logic minimization problems.
100 101
010 011
110 111
000 001
1110
00 010 1
0100 0101
0010
0011
0110
0111
0000 0001
1100
1101
1010
1011
1110 1111
1000
1001
1-cube 2-cube
3-cube 4-cube
Copyright © 2000 by Prentice Hall, Inc.Digital Design Principles and Practices, 3/e
n-Cubes And Distance• They provide a geometrical
interpretation for the concept of distance.
• Hamming distance is the number of positions in which two n bit strings differ.
• The distance between adjacent vertices is one. m-subcube of an n-cube is a set of 2m vertices in which n-m bits, of the bit strings representing those vertices, have the same value at each vertex.
100 101
010 011
110 111
000 001
1110
00 010 1
0100 0101
0010
0011
0110
0111
0000 0001
1100
1101
1010
1011
1110 1111
1000
1001
1-cube 2-cube
3-cube 4-cube
Copyright © 2000 by Prentice Hall, Inc.Digital Design Principles and Practices, 3/e
Codes For Detecting And Correcting Errors
• Error – corruption of data caused by physical failures.
• The effect failures on data are predicted by error models, and the independent error model is the simplest one.– In this model, a single physical
failure is assumed to affect a single bit of data.
– Notice that multiple failures may cause multiple errors, but multiple errors are normally assumed to be less likely to occur, than single errors.
Codes For Detecting And Correcting Errors
• Code word – a valid representation of the code.
• Non-code word – an invalid representation of the code.
• An n bit string does not have 2n
code words.• An error detecting code only
generates, transmits and stores code words, so errors can be detected by verifying if the bit string is a code word. If a non-code word is found then that word has an error.
Codes For Detecting And Correcting Errors• A code detects all single errors
if the minimum distance between all possible pairs of code words is 2.
• No single error can change one code word into another.
100 101
010 011
110 111
000 001
(b)
100 101
010 011
110 111
000 001
(a)
= code word
= noncode word
Codes For Detecting And Correcting Errors• In general n + 1 bits are needed to
construct a single-error-detecting code with 2n code words.
• XXXXX…XP– Where XXXXX…X are the
information bits, and P is the parity bit.
Information Even-parity Odd-parityBits Code Code000 000 0 000 1001 001 1 001 0010 010 1 010 0011 011 0 011 1100 100 1 100 0101 101 0 101 1110 110 0 110 1111 111 1 111 0
Error Correcting And Multiple Error Detecting Codes
• 2c + 1 is the minimum distance for an error correcting code capable of correcting c bits.
• 2c + d + 1 is the minimum distance for an error code capable of correcting up to cerrors and detecting up to dadditional errors.
Error Correcting And Multiple Error Detecting Codes
0001011
0001001
0000011
0001010
0011011
= code word
= noncode word
1011001
0011001
1001001
1011000
1010001
1010010
0001111 1111001
1010110
1010000
1011010
1010011
1001011 1011011
0010010
1000010
0101011 1011101
1110010
Copyright © 2000 by Prentice Hall, Inc.Digital Design Principles and Practices, 3/e
Error Correcting And Multiple Error Detecting Codes
00101011
00101010
00100011
10100011
11100011
11010011
11000011
detectable 2-bit errors
3-bit errorlooks like a1-bit error
all 1- to 3-bit errorsare detectable
detectable 2-bit errors
correctable 1-bit errors
(a)
(b)
(c)
00101011
00101010
00100011
10100011
11100011
11010011
11000011
00101011 11000011
Copyright © 2000 by Prentice Hall, Inc.Digital Design Principles and Practices, 3/e
Codes For Detecting And Correcting Errors• Hamming Codes.
– Method for constructing a code created by R.W. Hamming, in 1950.
– For any value of i this method yields a 2i – 1 bit code with icheck bits and 2i – 1 – i information bits.
• CRC Codes.– Cyclic-redundancy-check codes.– Includes Hamming codes in its
construction.– Used in hard disk drives and
data networks.
Codes For Detecting And Correcting Errors• Two dimensional codes.
– RAID – redundant array of inexpensive disks.
(a)
information bitscheckson rows
Rows arecode wordsin Crow
checkson checkschecks on columns
Columns are code words in Ccol
(b)
information bits
Rows arecode wordsin 1-biteven-paritycode
Columns are code wordsin 1-bit even-parity code
No effect on column parity
No effect onrow parity
(c)
Copyright © 2000 by Prentice Hall, Inc.Digital Design Principles and Practices, 3/e
information blocks
Disk 1
Disk 2
Disk 3
Disk 4
Disk 5
Disk 6
Disk n
Disk n + 1
Block number
1 2 3 4 5 6 7 8 . . . m9 10 1211
check blocks
. . .
. . .
. . .. . . One block
CRCData bytes
1 2 3 4 5 6 5127. . .. . .
Copyright © 2000 by Prentice Hall, Inc.Digital Design Principles and Practices, 3/e
Codes For Detecting And Correcting Errors
• Checksum codes.– Parity checking is a modulo two
addition of bits.• m-out-of-n codes.
– Detects unidirectional errors, bit changes in the same direction, for example, 0 changing to 1.
Codes for Serial Transmission of Data
bit number 1 2 3 4 5 6 7 8 1
bit cell bit cell bit cell bit cell bit cell bit cell bit cell bit cell bit cell
2
bit cell
time
bit time
SYNC
SERDATA
CLOCK
Copyright © 2000 by Prentice Hall, Inc.Digital Design Principles and Practices, 3/e
• CLOCK defines the rate of transmission, in bps, bits per second.
• SERDATA is the information being transmitted.
• SYNC identifies the first bit of information.
Codes for Serial Transmission of Data
• DPLL is an analog circuit used to extract the clock from a serial data stream.
• Codes for serial data:– NRZ, non-return-to-zero.– NRZI, non-return-to-zero
invert.– RZ, return-to-zero.– BPRZ, bipolar return-to-zero.– Manchester.
Codes for Serial Transmission of Data
NRZ
bit value 1 1 10 00 1 0
NRZI
RZ
Manchester
BPRZ
time
Copyright © 2000 by Prentice Hall, Inc.Digital Design Principles and Practices, 3/e