KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Check whether a number x is nonzero using the legal operators except ! . Examples: isNonZero(3) = 1 , isNonZero(0) = 0 Legal ops: ~ & ^ | + << >> Note : Only bitwise operators should be used. if , else , for , etc. cannot be used. Edit1 : No. of operators should not exceed 10. Edit2 : Consider size of int to be 4 bytes. int isNonZero(int x) { return ???; } Using ! this would be trivial , but how do we do it without using ! ?
Tags (comma-separated)
Save Edits
Cancel