#include <iostream>
// Rating: 1
/*
* bitAnd - x&y using only ~ and | 用~和|表示&
* Example: bitAnd(6, 5) = 4 0110 0101
* Legal ops: ~ |
* Max ops: 8
* Rating: 1
*/
int bitAnd(int x, int y) {
return ~(~x|~y);
}
/*
* bitXor - x^y using only ~ and & 用~和&表示^
* Example: bitXor(4, 5) = 1
* Legal ops: ~ &
* Max ops: 14
* Rating: 1
*/
int bitXor(int x, int y) {
return ~(x&y)&~(~x&~y);
}
/*
* thirdBits - return word with every third bit (starting from the LSB) set to 1
* 从左到右每三个位有一个1
* Legal ops: ! ~ & ^ | + << >>
* Max ops: 8
* Rating: 1
*/
int thirdBits(void) {
int result = 0x24;
result = (result << 8) + 0x92;
result = (result << 8) + 0x49;
result = (result << 8) + 0x24;
return result;
return 2;
}
// Rating: 2
/*
*
// Rating: 1
/*
* bitAnd - x&y using only ~ and | 用~和|表示&
* Example: bitAnd(6, 5) = 4 0110 0101
* Legal ops: ~ |
* Max ops: 8
* Rating: 1
*/
int bitAnd(int x, int y) {
return ~(~x|~y);
}
/*
* bitXor - x^y using only ~ and & 用~和&表示^
* Example: bitXor(4, 5) = 1
* Legal ops: ~ &
* Max ops: 14
* Rating: 1
*/
int bitXor(int x, int y) {
return ~(x&y)&~(~x&~y);
}
/*
* thirdBits - return word with every third bit (starting from the LSB) set to 1
* 从左到右每三个位有一个1
* Legal ops: ! ~ & ^ | + << >>
* Max ops: 8
* Rating: 1
*/
int thirdBits(void) {
int result = 0x24;
result = (result << 8) + 0x92;
result = (result << 8) + 0x49;
result = (result << 8) + 0x24;
return result;
return 2;
}
// Rating: 2
/*
*