Binary numbers and arithmetic.ppt
《Binary numbers and arithmetic.ppt》由会员分享,可在线阅读,更多相关《Binary numbers and arithmetic.ppt(50页珍藏版)》请在麦多课文档分享上搜索。
1、Binary numbers and arithmetic,addition,Addition (decimal),Addition (binary),Addition (binary),Addition (binary),So can we count in binary?,Counting in binary (4 bits),0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15,0000 0001 ,multiplication,Multiplication (decimal),Multiplication (binary),Multiplication (bina
2、ry),Its interesting to note that binary multiplication is a sequence of shifts and adds of the first term (depending on the bits in the second term.,110100 is missing here because the corresponding bit in the second terms is 0.,Representing signed (positive and negative) numbers,Representing numbers
3、 (ints),Fixed, finite number of bits.bits bytes C/C+ Intel Sun 8 1 char sbyte byte 16 2 short sword half 32 4 int or long sdword word 64 8 long long sqword xword,Representing numbers (ints),Fixed, finite number of bits.bits Intel signed unsigned 8 sbyte -27+27-1 0+28-1 16 sword -215+215-1 0+216-1 32
4、 sdword -231+231-1 0+232-1 64 sqword -263+263-1 0+264-1In general, for k bits, the unsigned range is 0+2k-1 and the signed range is -2k-1+2k-1-1.,Methods for representing signed ints.,signed magnitude1s complement (diminished radix complement)2s complement (radix complement)excess bD-1,Signed magnit
5、ude,Ex. 4-bit signed magnitude 1 bit for sign 3 bits for magnitude,Signed magnitude,Ex. 4-bit signed magnitude 1 bit for sign 3 bits for magnitude,1s complement (diminished radix complement),Let x be a non-negative number. Then x is represented by bD-1+(-x) where b = base D = (total) # of bits (incl
6、uding the sign bit)Ex. Let b=2 and D=4. Then -1 is represented by 24-1-1 = 1410 or 11102.,1s complement (diminished radix complement),Let x be a non-negative number. Then x is represented by bD-1+(-x) where b = base & D = (total) # of bits (including the sign bit) Ex. What is the 9s complement of 12
7、38910? Given b=10 and D=5. Then the 9s complement of 12389 = 105 1 12389 = 100000 1 12389 = 99999 12389 = 87610,1s complement (diminished radix complement),Let x be a non-negative number. Then x is represented by bD-1+(-x) where b = base D = (total) # of bits (including the sign bit) Shortcut for ba
8、se 2? All combinations used, but 2 zeros!,2s complement (radix complement),Let x be a non-negative number. Then x is represented by bD+(-x). Ex. Let b=2 and D=4. Then -1 is represented by 24-1 = 15 or 11112. Ex. Let b=2 and D=4. Then -5 is represented by 24 5 = 11 or 10112. Ex. Let b=10 and D=5. The
9、n the 10s complement of 12389 = 105 12389 = 100000 12389 = 87611.,2s complement (radix complement),Let x be a non-negative number. Then x is represented by bD+(-x). Ex. Let b=2 and D=4. Then -1 is represented by 24-1 = 15 or 11112. Ex. Let b=2 and D=4. Then -5 is represented by 24 5 = 11 or 10112. S
10、hortcut for base 2?,2s complement (radix complement),Shortcut for base 2? Yes! Flip the bits and add 1.,2s complement (radix complement),Are all combinations of 4 bits used? No. (Now we only have one zero.) 1000 is missing! What is 1000? Is it positive or negative? Does -8 + 1 = -7 work in 2s comple
11、ment?,excess bD-1 (biased representation),For pos, neg, and 0, x is represented bybD-1 + xEx. Let b=2 and D=4. Then the excess 8 (24-1) representation for 0 is 8+0 = 8 or 10002.Ex. Let b=2 and D=4. Then excess 8 for -1 is 8 1 = 7 or 01112.,excess bD-1,For pos, neg, and 0, x is represented by bD-1 +
12、x. Ex. Let b=2 and D=4. Then the excess 8 (24-1) representation for 0 is 8+0 = 8 or 10002. Ex. Let b=2 and D=4. Then excess 8 for -1 is 8 1 = 7 or 01112.,2s complement vs. excess bD-1,In 2s, positives start with 0; in excess, positives start with 1.Both have one zero (positive).Remaining bits are th
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- BINARYNUMBERSANDARITHMETICPPT
