网站大量收购闲置独家精品文档,联系QQ:2885784924

复旦大学软件学院计算机系统课件 Representing Information (2).ppt

复旦大学软件学院计算机系统课件 Representing Information (2).ppt

  1. 1、本文档共41页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
* * * * * * * * * * * * * * * * * * * * * Expanding the Bit Representation Zero extension Add leading 0s to the representation Sign extension [xw-1,xw-2,xw-3,?x0] ????? X X ? ????? ????? ????? - ????? X X ? - + ????? w+1 w * From short to long short int sx = 12345; :0x0309 int x = (int) sx; : 0short int sy =-12345;: 0xcfc7 int y = (int) sy; : 0xffffcfc7 usinged ux = sx; : 0xffffcfc7 * From short to long int fun1(unsigned word) { return (int) ((word 24) 24); } int fun2(unsigned word) { return ((int) word 24) 24; } w fun1(w) fun2(w) 0 0 0x000000C9 0xEDCBA987 Describe in words the useful computation each of these functions performs. 00000021 000000C9 FFFFFFC9 FFFFFF87 * From long to short int x = 53191; short int sx = x; int y = -12345; Short int sy = y; We need to truncate the data size Casing from long to short is trick * Truncating Numbers Decimal Hex Binary x 53191 00 00 CF C70000000011000111 sx -12345 CF C7 11000111 y -12345 FF FF CF C71111111111000111 sy -12345 CF C7 11000111 ????? X X ? ????? ????? * Truncating Numbers Unsigned Truncating Signed Truncating * Advice on Signed vs. Unsigned Non-intuitive Features float sum_elements ( float a[], unsigned length ) { int i ; for ( i = 0; i = length – 1; i++) result += a[i] ; } * Advice on Signed vs. Unsigned /* Prototype for library function strlen */ size_t strlen(const char *s); /* Determine whether string s is longer than string t */ /* WARNING: This function is buggy */ int strlonger(char *s, char *t) { return strlen(s) - strlen(t) 0; } * Advice on Signed vs. Unsigned 1 /* 2 * Illustration of code vulnerability similar to that found in 3 * FreeBSD’s implementation of getpeername() 4 */ 5 6 /* Declaration of library function memcpy */ 7 void *memcpy(void *dest, void *src, size_t n); 8

文档评论(0)

ormition + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档