⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 http:^^www.cs.wisc.edu^~cs354-2^cs354^lec.notes^represent.html

📁 This data set contains WWW-pages collected from computer science departments of various universities
💻 HTML
📖 第 1 页 / 共 2 页
字号:
Date: Tue, 05 Nov 1996 00:32:24 GMTServer: NCSA/1.5Content-type: text/htmlLast-modified: Wed, 30 Aug 1995 21:21:36 GMTContent-length: 15349<html><head><title> Lecture notes - Chapter 4 - Data Representation</title></head><BODY><h1> Chapter 4 -- representations</h1><pre>ALL ABOUT INTEGER REPRESENTATION.---------------------------------Computers operate on binary values (as a result of being built fromtransistors).there are different binary representations for integerspossible qualifications:  1. positive numbers only  2. positive and negative numbers  3. ease of human readability  4. speed of computer operationsthere are 4 commonly known (1 not common) integer reprentations.All have been used at various times for various reasons.   1. unsigned   2. sign magnitude   3. one's complement   4. two's complement   5. biased (not commonly known)virtually all modern computers operate based on 2's complement representation.  why?   1. hardware is faster   2. hardware is simplerUNSIGNED--------the standard binary encoding already givenonly positive valuesrange:   0 to 2**n - 1, for n bitsexample:   4 bits, values 0 to 15	   n=4, 2**4 -1 is 15	   binary decimal hex     binary decimal hex	   0000      0     0       1000    8      8	   0001      1     1       1001    9      9	   0010      2     2       1010    10     a	   0011      3     3       1011    11     b	   0100      4     4       1100    12     c	   0101      5     5       1101    13     d	   0110      6     6       1110    14     e	   0111      7     7       1111    15     fSIGN MAGNITUDE--------------a human readable way of getting both positive and negative integers.The hw that does arithmetic on sign magnitude integersis not fast, and it is more complex than the hw that does arithmeticon 1's comp. and 2's comp. integers.use 1 bit of integer to represent the sign of the integer    let sign bit of 0 be positive,		    1 be negative.the rest of the integer is a magnitude, uses same encodingas unsigned integersexample:  4 bits	      0101   is  5	      1101   is -5to get the additive inverse of a number, just flip   (not, invert, complement, negate) the sign bit.range:    -(2**(n-1)) + 1     to    2**(n-1) -1               where n is the number of bits      	  4 bits, -7 to +7	  n=4, - 2**3 + 1     to    2**3 - 1	       -8 + 1         to     8 - 1because of the sign bit, there are 2 representations for 0.This is a problem for hardware. . .    0000 is 0, 1000 is 0    the computer must do all calculations such that they    come out correctly and the same whichever representation is used.ONE's COMPLEMENT----------------historically important, and we use this representation to get  2's complement integers.Now, nobody builds machines that are based on 1's comp. integers.In the past, early computers built by Semour Cray (while at CDC)were based on 1's comp. integers.positive integers use the same representation as unsigned.          00000 is 0     00111 is 7,  etc.negation (finding an additive inverse) is done by taking a bitwisecomplement of the positive representation.  COMPLEMENT. INVERT. NOT. FLIP. NEGATE.       a logical operation done on a single bit	    the complement of 1 is 0.	    the complement of 0 is 1.	-1 -->        take +1,    00001	      complement each bit 11110              that is -1.	      don't add or take away any bits.	EXAMPLES:        11100         this must be a negative number.			       to find out which, find the additive			       inverse!		 00011   is +3 by sight,			 so 11100 must be -3  things to notice:  1. any negative number will have a 1 in the MSB.		     2. there are 2 representations for 0,			00000 and 11111.TWO's COMPLEMENT----------------a variation on 1's complement that does not have 2 representations for0.  This makes the hardware that does arithmetic faster than for theother representations.  a 3 bit example:  bit pattern:    100   101  110  111  000  001  010  011  1's comp:       -3     -2   -1    0   0    1    2    3  2's comp.:      -4     -3   -2   -1   0    1    2    3  the negative values are all "slid" down by one, eliminating the   extra zero representation.  how to get an integer in 2's comp. representation:    positive values are the same as for sign/mag and 1's comp.    they will have a 0 in the MSB (but it is NOT a sign bit!)    positive:   just write down the value as before    negative:	      take the positive value    00101 (+5)	      take the 1's comp.         11010 (-5 in 1's comp)	      add 1                     +    1					------					 11011 (-5 in 2's comp)  to get the additive inverse of a 2's comp integer,      1.  take the 1's comp.      2.  add 1  to add 1 without really knowing how to add:    start at LSB, for each bit (working right to left)      while the bit is a 1, change it to a 0.      when a 0 is encountered, change it to a 1 and stop.  EXAMPLE:       what decimal value does the two's complement 110011 represent?       It must be a negative number, since the most significant bit       is a 1.  Therefore, find the additive inverse:	     110011  (2's comp.  ?)	     001100  (after taking the 1's complement)		+ 1	     ------	     001101  (2's comp.  +13)	     Therefore, it's additive inverse (110011) must be -13.A LITTLE BIT ON ADDING----------------------  we'll see how to really do this in the next chapter, but here's  a brief overview.	carry in  a  b   sum  carry out	   0      0  0    0    0	   0      0  1    1    0	   0      1  0    1    0	   0      1  1    0    1	   1      0  0    1    0	   1      0  1    0    1	   1      1  0    0    1	   1      1  1    1    1       a      0011      +b     +0001      --     -----     sum      0100  its really just like we do for decimal!    0 + 0 = 0    1 + 0 = 1    1 + 1 = 2  which is 10 in binary, sum is 0 and carry the 1.    1 + 1 + 1 = 3  sum is 1, and carry a 1.BIASED REPRESENTATION---------------------an integer representation that skews the bit patterns so as tolook just like unsigned but actually represent negative numbers.    examples:    given 4 bits, we BIAS values by 2**3 (8)	  TRUE VALUE to be represented      3	  add in the bias                  +8					 ----	  unsigned value                   11	  so the bit pattern of 3 in biased-8 representation	  will be  1011      	  going the other way, suppose we were given a	  biased-8 representation as   0110	  unsigned 0110  represents 6	  subtract out the bias   - 8				  ----	  TRUE VALUE represented   -2    this representation allows operations on the biased numbers    to be the same as for unsigned integers, but actually represents    both positive and negative values.    choosing a bias:      the bias chosen is most often based on the number of bits      available for representing an integer.  To get an approx.      equal distribution of true values above and below 0,      the bias should be    2 ** (n-1)      or   (2**(n-1)) - 1SIGN EXTENSION--------------how to change an integer with a smaller number of bits into thesame integer (same representation) with a larger number of bits.this must be done a lot by arithmetic units, so it is best togo over it.by representation:  unsigned:             xxxxx   -->   000xxxxx	copy the original integer into the LSBs, and put 0's elsewhere  sign/magnitude:       sxxxx   -->   s000xxxx	copy the original integer's magnitude into the LSBs,	put the original sign into the MSB, and put 0's elsewhere  1's and 2's complement:   called SIGN EXTENSION.	copy the original integer into the LSBs,	take the MSB of original integer and copy it elsewhere.	example:       0010101		   000 0010101

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -