Datalab实验记录

CSAPP:Data Lab 记录 bitXor(x,y) 使用两种运算实现异或操作(&与~),要求指令数最多为14 //1 /* * bitXor - x^y using only ~ and & * Example: bitXor(4, 5) = 1 * Legal ops: ~ & * Max ops: 14 * Rating: 1 */ int bitXor(int x, int y) { int nx = ~x; int ny = ~y; int fx = x & ny; int fy = nx & y; return ~( (~fx) & (~fy) ); } 采用的是离散数学中亦或的另一种定义方式,$$P \oplus Q = (P \wedge \neg Q) \vee (\neg P \vee Q)$$....

December 17, 2021 · yunlang