2013年8月13日
摘要: Given a (decimal – e.g. 3.72) number that is passed in as a string, print the binary representation.If the number can not be represented accurately in binary, print “ERROR”.string print_binary(string val){ int pos = val.find('.',0); int intpart = atoi(val.substr(0,pos).c_str()); double doub. 阅读全文
posted @ 2013-08-13 15:12 xuanxu 阅读(170) 评论(0) 推荐(0) 编辑
摘要: 给定两个32位的数,N和M,还有两个指示位的数,i和j。 写程序使得N中第i位到第j位的值与M中的相同(即:M变成N的子串且位于N的第i位和第j位之间) 1 int updateBits(int n,int m,int i,int j) 2 { 3 int max = ~0; 4 int left = max -((1<<j+1)-1); 5 int right = 1<<i -1; 6 7 int mask = left|right; 8 9 return (n&mask)|(m<<i);10 } 阅读全文
posted @ 2013-08-13 14:52 xuanxu 阅读(130) 评论(0) 推荐(0) 编辑