Hello, I am trying to solve a problem that has to do with bit representation and
ID: 3549338 • 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.
this is what I have come up with so far but am not having any luck:
Explanation / Answer
please rate - thanks
you didn't specify the language
my sampkle is C++
but the functions are identical in C or C++
#include<iostream>
using namespace std;
int bitXor(int x,int y)
{return ~(~(x&~y)&~(~x&y));
}
int bitOr(int x,int y)
{return ~(~x&~y);
}
int main()
{
cout<<bitXor(4,5)<<endl;
cout<<bitXor(7,12)<<endl;
cout<<bitOr(5,3)<<endl;
cout<<bitOr(9,20)<<endl;
system("pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.