Hello, I am trying to solve a problem that has to do with bit representation and
ID: 3549303 • Letter: H
Question
Hello,
I am trying to solve a problem that has to do with bit representation and it has certain limits, as to what kind of controls and the amount that I can use for this particular problem. These controls linclude:
Using if, do, while, for, switch, etc.
defining additional functions
calling any functions
using any form of casting
using operations such as &&, ||, -, or ?:
using any data type other than int
defining or using macros
My goal is to replace the "return" statement in each function with one or more lines of c code that implements the function.
here is my problem:
bitAnd - x&y using only ~ and |
example: bitAnd(6, 5) = 4
legal operations: ~ |
max operations: 8
int bitAnd(int x, int y)
//code implementation
return 2
I am confused as to how to look at this problem or how to start. Does anyone have any suggestions? Could you walk me through the problem?
Thanks, :-)
Explanation / Answer
int bitAnd(int x, int y) { return ~(~x | ~y); }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.