CSAPP: 位操作实现基本运算
目录 实验要求 实现代码 1、pow2plus1 2、pow2plus4 3、bitXor 4、tmin 5、isTmax 6、allOddBits 7、negate 8、isAsciiDigit 9、conditional 10、isLessOrEqual 11、logicalNeg 12、howManyBits 13、floatScale2 14、floatFloat2Int 15、floatPower2 @(位操作实现简单函数) 实验要求 给出15个函数,规定了实现每个函数需要的逻辑和算术操作符(规定数量)。 只能使用规定的操作符! ˜ & ˆ | + << >> 不能使用循环或者条件语句 不能使用超过8位的常数(ff) 实现代码 1、pow2plus1 /* * pow2plus1 - returns 2^x + 1, where 0 <= x <= 31 */ int pow2plus1(int x) { /* exploit ability of shifts to compute powers of 2 */ return (1 << x) + 1; } 2、pow2plus4 /* * pow2plus4 - returns 2^x + 4, where 0 <= x <= 31 */ int pow2plus4(int x) { /* exploit