I am just lost on this one, its got me baffled.
A function is passed a Signed 32 bit integer.
This function must return EXACTLY 1 or 0 (i.e. it returns int not bool)
You are allowed to use the following bitwise operations a maxium of 10 times.
You can create as many Variables as needed, and can use the assignment operator as many times as needed.Code:
Legal ops: ~ & ^ | + << >>
You cannot use any conditional operators (if() ()?: while() for() etc...)
Detect if the given integer is non-zero or 0.
Essentially use only bitwise operations and return an integer that is either 1 or 0 to indicate if the passed integer is non zero or not.
Now i have personally had a very tough time with this one, and if anyone has any idea how to solve it, or an idea on how to do it, please share =).
Good luck :confused:
EDIT: The Biggest problem i am having is that with only 10 operations i can't find a (foolproof) way to check enough bits to ensure i won't miss one on the odd chance that said number falls on the single bit i don't check.
Thanks again for any info.