CSE351 - Lab 1: Manipulating Bits Using C
今天做了CSE351 - Lab1,深深的感觉国外的计算机教学爆了我校一条街。
以上是前言。
bitAnd & bitOr
德摩根定理的应用
/*
* bitAnd - x&y using only ~ and |
* Example: bitAnd(6, 5) = 4
* Legal ops: ~ |
* Max ops: 8
* Rating: 1
*/
int bitAnd(int x, int y) {
return ~(~x | ~y);
/*
* bitOr - x|y using only ~ and &
* Example: bitOr(6, 5) = 7
* Legal ops: ~ &
* Max ops: 8 …