Check if a number x is positive (x>0) by ONLY using bitwise operators in C

Viewed 36876

isPositive - return true if x > 0, otherwise false

Example: isPositive(-1)

Legal ops: ! ~ & ^ | + << >>

Max ops: 8

Note: No conditional statements are allowed.

inline bool isPositive(int32_t x) {
  return ???;
}
12 Answers
Related