Chapter 2Bits, Data Types,and Operations.ppt
《Chapter 2Bits, Data Types,and Operations.ppt》由会员分享,可在线阅读,更多相关《Chapter 2Bits, Data Types,and Operations.ppt(33页珍藏版)》请在麦多课文档分享上搜索。
1、Chapter 2 Bits, Data Types, and Operations,2-2,How do we represent data in a computer?,At the lowest level, a computer is an electronic machine. works by controlling the flow of electronsEasy to recognize two conditions: presence of a voltage well call this state “1” absence of a voltage well call t
2、his state “0”Could base state on value of voltage, but control and detection circuits more complex. compare turning on a light switch to measuring or regulating voltage,2-3,Computer is a binary digital system.,Basic unit of information is the binary digit, or bit. Values with more than two states re
3、quire multiple bits. A collection of two bits has four possible states: 00, 01, 10, 11 A collection of three bits has eight possible states: 000, 001, 010, 011, 100, 101, 110, 111 A collection of n bits has 2n possible states.,Binary (base two) system: has two states: 0 and 1,Digital system: finite
4、number of symbols,2-4,What kinds of data do we need to represent?,Numbers signed, unsigned, integers, floating point, complex, rational, irrational, Text characters, strings, Images pixels, colors, shapes, Sound Logical true, false Instructions Data type: representation and operations within the com
5、puter Well start with numbers,2-5,Unsigned Integers,Non-positional notation could represent a number (“5”) with a string of ones (“11111”) problems?Weighted positional notation like decimal numbers: “329” “3” is worth 300, because of its position, while “9” is only worth 9,3x100 + 2x10 + 9x1 = 329,1
6、x4 + 0x2 + 1x1 = 5,most significant,least significant,2-6,Unsigned Integers (cont.),An n-bit unsigned integer represents 2n values: from 0 to 2n-1.,2-7,Unsigned Binary Arithmetic,Base-2 addition just like base-10! add from right to left, propagating carry,10010 10010 1111+ 1001 + 1011 + 111011 11101
7、 1000010111+ 111,carry,Subtraction, multiplication, division,2-8,Signed Integers,With n bits, we have 2n distinct values. assign about half to positive integers (1 through 2n-1) and about half to negative (- 2n-1 through -1) that leaves two values: one for 0, and one extra Positive integers just lik
8、e unsigned zero in most significant (MS) bit 00101 = 5 Negative integers sign-magnitude set MS bit to show negative, other bits are the same as unsigned 10101 = -5 ones complement flip every bit to represent negative 11010 = -5 in either case, MS bit indicates sign: 0=positive, 1=negative,2-9,Twos C
9、omplement,Problems with sign-magnitude and 1s complement two representations of zero (+0 and 0) arithmetic circuits are complex How to add two sign-magnitude numbers? e.g., try 2 + (-3) How to add to ones complement numbers? e.g., try 4 + (-3) Twos complement representation developed to make circuit
10、s easy for arithmetic. for each positive number (X), assign value to its negative (-X), such that X + (-X) = 0 with “normal” addition, ignoring carry out,00101 (5) 01001 (9)+ 11011 (-5) + (-9)00000 (0) 00000 (0),2-10,Twos Complement Representation,If number is positive or zero, normal binary represe
11、ntation, zeroes in upper bit(s) If number is negative, start with positive number flip every bit (i.e., take the ones complement) then add one,00101 (5) 01001 (9)11010 (1s comp) (1s comp)+ 1 + 1 11011 (-5) (-9),2-11,Twos Complement Shortcut,To take the twos complement of a number: copy bits from rig
12、ht to left until (and including) the first “1” flip remaining bits to the left,011010000 011010000100101111 (1s comp) + 1 100110000 100110000,(copy),(flip),2-12,Twos Complement Signed Integers,MS bit is sign bit it has weight 2n-1. Range of an n-bit number: -2n-1 through 2n-1 1. The most negative nu
13、mber (-2n-1) has no positive counterpart.,2-13,Converting Binary (2s C) to Decimal,If leading bit is one, take twos complement to get a positive number. Add powers of 2 that have “1” in the corresponding bit positions. If original number was negative, add a minus sign.,X = 01101000two= 26+25+23 = 64
14、+32+8= 104ten,Assuming 8-bit 2s complement numbers.,2-14,More Examples,Assuming 8-bit 2s complement numbers.,X = 00100111two= 25+22+21+20 = 32+4+2+1= 39ten,X = 11100110two -X = 00011010= 24+23+21 = 16+8+2= 26tenX = -26ten,2-15,Converting Decimal to Binary (2s C),First Method: Division Find magnitude
15、 of decimal number. (Always positive.) Divide by two remainder is least significant bit. Keep dividing by two until answer is zero, writing remainders from right to left. Append a zero as the MS bit; if original number was negative, take twos complement.,X = 104ten 104/2 = 52 r0 bit 052/2 = 26 r0 bi
16、t 126/2 = 13 r0 bit 213/2 = 6 r1 bit 36/2 = 3 r0 bit 43/2 = 1 r1 bit 5X = 01101000two 1/2 = 0 r1 bit 6,2-16,Converting Decimal to Binary (2s C),Second Method: Subtract Powers of Two Find magnitude of decimal number. Subtract largest power of two less than or equal to number. Put a one in the corresp
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- CHAPTER2BITS DATATYPES ANDOPERATIONSPPT
