If you can't read please download the document
Upload
zion
View
125
Download
14
Embed Size (px)
DESCRIPTION
版权所有,引用请注明出处. 第二章、计算机数据表示方法. 原著 谭志虎. 主讲 ( 改编 ) 蒋文斌. Outline. 2.1 非数值数据表示法 2.2 数值数据表示法 2.3 数据信息的校验. Data Representation. Qualitative Quantitative Integers Signed Unsigned Non-integers (Real) Signed Unsigned. 2.1 非数值数据表示法. 字符表示法 characters - PowerPoint PPT Presentation
Citation preview
()
Outline2.1 2.2 2.3
Data Representation QualitativeQuantitativeIntegersSignedUnsignedNon-integers (Real)SignedUnsigned
2.1 characters Chinese characters
2.1.1 Character representation StandardsASCII-American Standard Code for Information Interchange (ANSI 7bits)EBCDIC-Extended Binary-Coded Decimal Interchange Code (IBM 8bits)Unicode
128 Standard ASCII codes52 Lettersa-z, A-Z 10 Digits0-934 Symbols! @ # $ % ^ & * ( ) 32 Control characters
ASCII7bit128From 000 0000 to 111 1111 27=128ASCII1288Bit??? MSF=0
Terminologybit (Binary DigiT) (MSB) (LSB)
2.1.2 8 bit2566000GB231216ASCIIMSB=1()()
GB2312-801981GB2312-806763/682GB231237553008682
GB2312-1980(GB0)()6763 GB13000-199320902 (Unicode 1.1)GBK1.0 199521003GB2312GB18030-2000(1/2/4)27484 GB2312 GBKGB13000
16*1632
Charset
charset=gb2312 charset=big5 charset=EUC_KR charset=Shift_JIS EUC_JP charset=KOI8-R/Windows-1251 charset=iso-8859-2 charset=utf-8 unicode
Unicode www.unicode.org16 bit 65536 Unicode
Universal Character Set ISOUCS ISO 10646 UCS-2 UCS-4UTF (Unicode Transform format)UTF-7UTF-8UTF-16
TerminologyUUEncode/UudecodeMIME(Multipurpose Internet Mail Extensions )
2.2
: (
Human vs. Computer1010 ON OFF
012345678910
=C102+10=10*9/2!+10=55C82+8=8*7/2!+8=36C42+4=4*3/2!+4=10C22+2=2*1/2!+2=3
01 ( ()0+1=1+0=1 1+1=0 0+0=0(1055)
: Ai Bi Ci: Si Ci+1
Ai
Bi
Ci
Ci+1
Si
N r (Radix)i Di iri i 1 Di*ri i m+k+1
(10456)1011040103 410251016100(0xF96)16F1629161 6100(10010001)2127026 025 124 023 022 021 120
(10 011 100 . 01)2 = ( 234 . 2 )8 010
(1001 1100 . 01)2 = ( 9C . 4 )16 0100
10010001127026 025 124 023 022 021 120
2 252100.625 * 210.25 * 200.5 * 21 0.0 1011
17/128???22532 2664 27128 28256 29512 2101024(1Kilo) 2112048 21240962138182 21416364 2153272821665536 2201048576(1Mega)2301073741824(1Giga) 2401Tera2501 Peta 2601 Exa 2701 Zetta 2801 Yotta
Kilo, Mega, Giga, Tera, Peta, Exa, Zetta, Yotta physics.nist.gov/cuu/Units/binary.html30GB=???Byte 1Mbits=???30 GB drive30 x 109 28 x 230 bytes 1 Mbit/s = 106 bpsSI
1999 New IEC Standard Prefixes http://en.wikipedia.org/wiki/Binary_prefixSI (International System of Units )10234?2.5 TiB
-17/128=-0.001000165539=65536+3=10000000000000011 111111111110=111111111111-1=212-1-1=4046130=128+2=10000010111111110111212-1-82003=2047-44=111111111111-32-8-4
2.2
2.2.1 ()Signed & Unsigned
2-n |X|1-2-n/
X = X 0 . X1 X 2 X n X i={0,1}, 0in =X 12-1 + + X n-12-n+1 + X n 2-n
0|x| 1-2-n
1 |X|2n-1
X = X1X2Xn Xi={0,1}, 0in=X12n-1 + + Xn-121 + Xn
0|x|2n-1
?????
910-28g21033g0.21034N=10EMN=RemMeR
N=Rem=2EM =2e (m)
E0M0
- +0N=2EM|N| E + E - |N|0
Range & precisionE0M0
Example 80.0000001 --- 0.1111111 1/128 --- 127/128242-11*0.0001 --- 211*0.1111 0.0000001 --- 111.1332-111*0.001 --- 2111*0.111 0.0000000001 --- 1110000
normalization 0.05*101 50*10-2 5*10-1 0.01*21 1*2-2 1*2-1 1 1.XXXXX 0.1XXXXX 0
IEEE75432/64Float/DoubleN = (-1)SX M X 2E EMS
IEEE754(Normal)(-1)s1.m2e-127(Subnormal)(e=0)(-1)s0.m2-126
emin=1, emax=254/204611(implicit)
+0/-0000/1(-1)S (0.f) 2(-126)f()00/1(-1)S (1.f) 2(e-127)f1~2540/1- 02551+02550sNaN Signaling NaN0xxxx2550/1NaN Not a Number1xxxx2550/1
IEEE754 Emax=2046,f=1.1111,1.111122046-1023 =21023(2-2-52) Emin=1, M=0, 1.021-1023 =2-1022
Emax=254, f=1.1111, 1.11112254-127 = 2127(2-2-23) Emin=1, M=0, 1.021-127 = 2-126
main(){ double a,b,c; int d; b=3.3; c=1.1; a=b/c; d=b/c; printf("%f,%d",a,d); if (3.0!=a) printf("\nReally? 3.0!-a");}3.000000,2??????????Really?3.0!=a
main(){ float a,b,c; int d; b=3.3; c=1.1; a=b/c; d=b/c; printf("%f,%d",a,d); if (3.0!=a) printf("\nYeah!");}3.000000,2
2.2
2.2.2 / ()+ - () Signed magnitude Ones complement Twos complement Biased notation
Signed magnitude? Add a sign bit01
[+0]=0.0000[-0]=1. 0000[-0.1111] = 1.1111[ 0.1111] = 0.1111[ 1110] = 01110[-1110] = 11110
x = (-1)X0( x12n-1 + + xn-12 +Xn) x = (-1)X0( x12-1 + + xn-12-(n-1) +Xn2-n)
-7~+7 77 -(2(n-1) -1) ~2(n-1) -1
_1096037015.doc
7
-7
15
7
0
0
Signed MagnitudeBoth positive and negative zeroEqual number of positives and negativesEasy to interpretFirst bit is the signRemaining bits are numberSounds ideal? But01011001+11001101=???
Signed Magnitude?
010110012 = 8910 + 110011012 = -7710 001001102 = 3210If signs are different sign of result will be sign of larger operand
Shortcomings of signed magnitude?Arithmetic circuit complicatedAlso, two zeros0x00000000 = +0ten0x80000000 = 0ten What would two 0s mean for programming?
Therefore sign and magnitude abandoned
,Example: 710 = 001112 -710 =110002Called Ones Complement
0[+0]=0.0000[-0]=1.1111[0.1111]=0.1111[-0.1111]=1.0000[1110]=01110[-1110]=10001
([X]= x0x1 xn-1 Xn) x = -x02n -1+ x12n-1 + + xn-12 +Xn
-7~+7 77 -(2n -1) ~2n -1
0
-7
15
7
7
0
&
_1096037015.doc
7
-7
15
7
0
0
0
-7
15
7
7
0
Shortcomings of Ones complement?Arithmetic still a somewhat complicated.Still two zeros 0x00000000 = +0ten 0xFFFFFFFF = -0ten Although used for awhile on some computer products, ones complement was eventually abandoned because another solution was better.
315-9 12369
abma,bm, ab (mod m) X,Y,ZZ=nX+Y (n),ZYX ZY (mod X) YZ (mod X)
Z=nX+Y X123=12+3=24+3=36+33152739 -9=12-9=3 -930=12
7+(-4) =7+(12-4) =7+8 =15=3
3. ([X]= x0x1 xn-1 Xn)x = -x02n + x12n-1 + + xn-12 +Xn 10000100-128+4=-124
-8~+7 781 -2n ~2n -1
-8
7
15
7
0
0
-8
7
15
7
0
0
0
-7
15
7
7
0
LSB1
[-10101010]=1 01010101+1=1 01010110 [-0.010101]=1.101011
[x]=2-2-n+x[x]=2+x =(2-2-n+x)+2-n =[x]+2-n[x]=2n+1-1+x[x]=2n+1+x =(2n+1-1+x)+1 = [x]+1
X=+0.11111111 [X] =??? [X] =0.11111111
X=-0.11111111 [X] =??? [X] =1.00000000 +0.00000001 =1.00000001X=-0.00000000 [X] =??? [X] =1.11111111 +0.00000001 =10.00000000 =0.00000000
32 bit MIPS signed numbers 0000 0000 0000 0000 0000 0000 0000 0000two = 0ten 0000 0000 0000 0000 0000 0000 0000 0001two = + 1ten 0000 0000 0000 0000 0000 0000 0000 0010two = + 2ten ... 0111 1111 1111 1111 1111 1111 1111 1110two = + 2,147,483,646ten 0111 1111 1111 1111 1111 1111 1111 1111two = + 2,147,483,647ten 1000 0000 0000 0000 0000 0000 0000 0000two = 2,147,483,648ten 1000 0000 0000 0000 0000 0000 0000 0001two = 2,147,483,647ten 1000 0000 0000 0000 0000 0000 0000 0010two = 2,147,483,646ten ... 1111 1111 1111 1111 1111 1111 1111 1101two = 3ten 1111 1111 1111 1111 1111 1111 1111 1110two = 2ten 1111 1111 1111 1111 1111 1111 1111 1111two = 1ten
400.1010110 11.0101001
[0.0000]= [-0.0000]= 0.0000[1.0000]= 1.0000
[X + Y]= [X]+ [Y][X-Y]= [X]+ [-Y]
4. Biased/Excess Notation [x] = 2n+x -2n x < 2n
X=+10101 [X] =25+10101=110101X=-10101 [X] =25-10101 0101000001 001011
15
7
-8
0
0
+3-103111+2-212110+1-3211010-430100-1+3+3+3011-2+2+2+2010-3+1+1+1001-40+0+0000BinaryNumber StoredNumber Represented
X0.X1X2X3Xn-1Xnn+1n[2-n-1, 1-2-n] (-1,1)[-1, 1-2-n][-1,1) 2+x
X0X1X2X3Xn-1Xnn+1n[1-2n, 2n-1] (-2n, 2n)[-2n, 2n-1][-2n, 2n) 2n +x
,,,,,,,,,,
0.000011110.000011110.00001111+0.00001111100001111000001111000001111000001111+000011111.111100001111100000111100011.111100011111100011.00001111100001111-0.00001111-00001111
2.2.3 BCDBinary coded decimalBCD8421 (8*X3+4*X2+2*X1+1*X0)2421 (2*X3+4*X2+2*X1+1*X0) (8*X3+4*X2+2*X1+1*X0)+0011BCD()
BCD842187100001111111 00001100110110 3 44011101111110
2.3 CRC
2.3.1 10000 000010001 00010:::G=0
00001000010000100000011111111100001
2.3.2 Hamming Codes1950
rrr>102
NkrrrN=k+r2r1(4,3)D4D3D2D1P3P2P1H7H6H5H4H3H2H1G3G2G1P3P2P1
H7G3 G2 G1H6G3 G2H5G3 G1H3G2 G1G2G1=0 P3G3G1=0 P2G3G2=0 P1H7111H6110H5101H3011P3H4H4100P2H2H2010P1H1H1001000G3G2G1
G1(P1,H3,H5,H7)G2(P2,H3,H6,H7)G3(P3,H5,H6,H7)P1P2D1P3D2D3D4P1=D1D2D4P2=D1D3D4P3=D2D3D4
G1=P1D1D2D4G2=P2D1D3D4G3=P3D2D3D4G3G2G1 !=000D1D2G3G2G1=110 P4=H1H2H3H4H5H6H7G4=P4H1H2H3H4H5H6H7
CRCkrN=k+r2r1
2211 ,0 10000101=101*101+01
kM(x)M(x)=bk-1Xk-1 + bk-2Xk-2 + b1X1 + b0rrM(x)X r M(x)X rG(x)Q(x) R(x) M(x)X r=Q(X)G(x)+R(X)M(x)X r+R(X)=(Q(X)G(x)+R(X))+R(x) Q(X)G(x) CRCG(x)
(7,4)G(x)=1011110101000102111100001031101110010401111010105100110011060101100000700111000110001100010A1~A70110100
02(n,k)Xn-1
x7-1=(x+1)(x3+x+1)(x3+x2+1)G(x)=x+1=11 (7,6)G(x)= x3+x+1 G(x)(x3+x2+1)(7,4)G(x)=(x+1)(x3+x+1)=11101(7,3)
Example(7,3)3M(x)=110CRCG(x)=11101
(7,3)G(x)=1110160010110101170001110100000001101001A1~A71+2+3010000100015+6+7011111011101+6110001010112+3101010110013+4010111100014+5110011001015+6011011011116+700111101010A7~A1
CRC(Cyclic Redundancy Check ()
2XX/2 X/64 CRCBCD
Example1998-11.44,12
-11.4=-1011.01100111-11.4=-0.101101100111*24-11.4=-1.01101100111*23-11.4=-1.01101100111*23-11.4=-01101100111*23-11.4=1,01101100111*23M=1,01101100111 E=3=1,011
(-1)s1.m2e 1.1111111111127 =(2-2-11) 27 1.000000000002-8 = 2-8