1、CS1104 Computer Organization 1Number System and Coding Number system consists of an ordered set of digits, with relations defined for +, -, * and /. The radix (r) or base of a number system indicates the total number of digits allowed in the number system. Common number system include:- decimal- bin
2、ary- octal - hexadecimalPositional NotationsWeighted-Positional notation Decimal Number System - symbols used: 0,1,2,3, 9 Position of each digit is important.e.g. (40982) = 4x10 + 0X10 + 9X10 + 8X10 +2X10In general: (an an-1 an-2 a0)10 = (anx10 ) + (an-1x10 )+(a0x10 )FractionsFractions are written i
3、n decimal numbers after the decimal point.e.g. 333/4 = (33.75)10= (3x10 ) + (3x10 ) + (7x10 ) + (5x10 )In case of recurring fraction, use for recurring position.e.g. 21/3 = (2.333333)10= (2.3)10In general, (an an-1a0.f1 f2 fm)10 = (anx10 )+(an-1x10 )+(a0x10 )+(f1x10 )+(fmx10 )Conversion Between Base
4、s In general, conversion between bases can be done via:104 3 2 1 0n n-1 01202-12-22.n n-1 0 -1 -mBase-2Base-3Base-rBase-2Base-3Base-rDecimal.CS1104 Computer Organization 2Base r DecimalBinary(base 2) DecimalGeneral: (an an-1 an-2 a0.f1 f2fm)2 = (anx2 ) + (an-1x2 )+(a0x2 )+ (f1x2 )+(f2x2 )+(fmx2 )e.g
5、 (10110.01)2 = (1x2 )+(1x2 )+(1x2 )+(1x2 )= (22.25)10Octal(base 8) Decimale.g. (47.5)8 = (4x8 )+(7x8 )+(5x8 )= (39.625)10Hexadecimal(base 16) Decimale.g (BAD2.C)16 = (11x16 )+(10x16 )+(13x16 )+(2x16 )+(12x16 )= (47826.75)10Note: Hexadecimal digits are 0,1,2,3,4,5,6,7,8,9,A.B,C,D,E,F where A=10, B=11
6、,C=12,D=13,E=14,F=15.Generally, for Base r Decimal,(an an-1 an-2 a0.f1 f2fm)r = (an x r ) + (an-1 x r )+(a0 x r )+ (f1 x r )+(f2 x r )+(fm x r )Decimal Base rGenerally, (an an-1 a0.f1 f2 fp)10 (bm bm-1 b0.g1 g2 gq)rNote that Integers(whole number) and fractions are converted separately.i.e. (an an-1
7、 a0)10 (bm bm-1 b0)r(f1 f2 fp)10 (g1 g2 gq)rDecimal Binary(base 2)e.g. convert (41.375)10 to binary representation1.Integer partmethod: Coefficients obtained from remainders of successive division by 2. The first remainder is the least significant bit(LSB) and the last remainder is the most signific
8、ant bit(MSB).(41)10 = (101001)241/2 =20 rem 120/2 =10 rem 010/2 =5 rem 05/2 =2 rem 1n2n-2202-12-22-m2422212-2212n2-1232221202-1202n-1202 -12-22-m2Integer partFraction partCS1104 Computer Organization 32/2 =1 rem 01/2 =0 rem 1Hence result: (101001)2 2.Fractional partmethod: Coefficients of binary fra
9、ction obtained by successive multiplication of decimal fraction by 2. Coefficient will appear as integer portion of successive multiplication.(.375)10 = (.011)2 .375 x 2 = 0.75 0 MSB.75 x 2 = 1.5 1.5 x 2 = 1.0 1 LSBHence result: (.011)2In general: Decimal Base r- whole number: repeated division by r
10、- fractions : repeated multiplication by rBinary Octal / Hexadecimal ConversionOctal- 1 octal digit = 3 binary digits(bits)e.g. (001)2 = (1)8 (101)2 = (5)8(010)2 = (2)8 (111)2 = (7)8Techniques for converting binary octal group 3-bits and convert into corresponding octal digit.e.g. (10 110 001 101 01
11、1 111 100 000 1)2=(2 6 1 5 3 7 4 0 4)8Hexadecimal- 1 hexadecimal digit = 4 bitse.g. (1111)2 = (F)16 (1000)2 = (8)16(1010)2 = (A)16 (0010)2 = (2)16Techniques for converting binary hexadecimal group 4-bits and convert into corresponding hexadecimal digit.e.g. (10 1100 0110 1011 . 1111 0000 01)2 =(2 C
12、6 B F 0 4)16CS1104 Computer Organization 4Negative NumbersSign&MagnitudeNegative numbers are usually written by prepending a MINUS SIGN(-) in front.e.g. (7)10, -(0111)2In computer memory of fixed width, this sign is usually represented by a bit.- 0 for +- 1 for - Given a 8-bit number, MSB is the sig
13、n bit and the remaining 7 bits are magnitude.Note: to negate a number, just invert the sign bite.g. (0 0110010) = (1 0110010)sm(1 0111010) = (0 0111010)sm1s ComplementGiven an n-bit number, x, its negative number can be obtained in 1s complement representation using:x = 2 x 1e.g. given an 8-bit numb
14、er: (01001100)2 = (96)10= (2 96 1) 10=(159)10=(10110011)1sTechnique is INVERT all bits.(10 or 0 1) (01010101)2 = (10101010)1sNote, given a positive n-bit binary number, its 1s complement representation is still the same as the binary number.e.g. +(00011001)2 = (00011001)1s2s ComplementGiven an n-bit
15、 binary number, x, its negative number can be obtained in 2s complement representation using:x = 2 x e.g. given an 8-bit number: (01001100)2 = (96)10= (2 96)10= (160)10= (10110100)2sTechnique is INVERT all the bits and ADD 1e.g. (01010101)2 = (10101010)1s (invert)= (10101011)2s (add 1)n282n282CS1104
16、 Computer Organization 5Note: Given a positive n-bit number, its 2s complement representation is still the same as the binary number.e.g. +(00100100)2 = (00100100)2sComplementIn general, for base-r number, there are:- Diminished Radix (or r-1s) complement- Radix (or rs) complementDiminished Radix Co
17、mplementGiven an n-digit number, (N)r, its (r-1s) complement is:(r 1) Ne.g. The (r-1s) complement, or 9s complement of (15)10 is:(10 1) 15 = 99 5= (84)9sThe (r-1s) complement, or 7s complement of (327)8 is:(8 1) (327)8 = 777 327= (450)7sRadix ComplementGiven an n-digit number, (N)r, its rs complemen
18、t is:r Ne.g. The rs complement, or 10s complement of (15)10 is:10 15 = 100 15= (85)10sTechnique is use: (r-1s) complement + 1e.g. The 8s complement of (57)8 is:(8 1) (57)8 = 77 57 (7s complement)= (20)7s + 1 (add 1)= (21)8s (8s complement)Subtraction - Using r-Complement- Using r-1 ComplementSubtrac
19、tion using r-ComplementTechnique: Given 2 unsigned base-r numbers, M & N, Subtraction of (MN) is done by:1. add M to the r-complement N: M + (r N) = (MN) + r 2. if M = N, then there will be an end-carry r . So discard this end carry.3. if M N, then there will be an end-carry r . So discard this end
20、carry and add 1 to get: (MN1) + 1 = M N3. if M = N, then there is no end carry, but have ve result(incl 0): (M-N-1)+ r To get the normal form, take (r-1) complement to get: (r 1) (MN) + r ) = N-M. Then put MINUS sign in front(if result is not 0).e.g.(33)10 (22)10 = 33 +(99-22)9s= (33 + 77)9s= (110)9
21、s (discard end carry, add 1)= (10 +1)10= (11)10(10)10 (22)10 = 10 + (99 22)9s= (10 + 77)9s= (87)9s (no end carry, so complement it)= -(99 87)10= -(12)10Fixed Point NumbersSigned and unsigned numbers representation are fixed point numbers. The binary point is assumed to be at a fixed position.222222n
22、2n2n2n2n2n2 n2n2Binary point22CS1104 Computer Organization 7But the binary point can also be in other locations.e.g. 123.23, 12.323Cons of fixed point numbers: It have limited range.To represent very large numbers or very small numbers, need to use floating point numbers.e.g. 0.23 x 10 (very large p
23、ositive number)-0.1236 x 10 (very small negative number|)Floating Point Numbers- consist of 3 parts: mantissa, base and exponent.Since base is usually fixed, only need mantissa and exponent.Mantissa is usually in normalized form. i.e. 23 x 10 is normalized to 0.23 x 10 -0.0017 x 10 is normalized to
24、0.17 x 10A 32-bit number can have 24-bit mantissa and 8-bit exponent.More bits in exponent gives larger range.More bits in mantissa gives better precision.Floating Point Arithmetic Addition Steps: (i) equalise the exponents(ii) add-up the mantissa(iii) normalisee.g:(0.12 x 103)10 + (0.2 x 102)10 = (
25、0.12 x 103)10 + (0.02 x 103)10 (equalise exponents)= (0.12 + 0.02)10 x 103 (add mantissa)= (0.14 x 103)10 MultiplicationSteps: (i) multiply the mantissa(ii) add-up the exponents(iii) normalisee.g:(0.12 x 102)10 x (0.2 x 1030)10 = (0.12 x 0.2)10 x 102+30 = (0.024)10 x 1032 (normalise)= (0.24 x 1031)1
26、0 232 -102212232 212192CS1104 Computer Organization 8Error Detection Codes Errors can occur during data transmission. They should be detected, so that re-transmission can be requested. With binary numbers, usually single-bit errors occur.e.g. 0010 erroneously transmitted as 0011, or 0000, or 0110, or 1010.For single-error detection, one additional bit is needed.Parity bit.Even parity: additional bit supplied to make total number of 1s even.Odd parity: additional bit supplied to make total number of 1s odd.