Checking whether a number is positive or negative using bitwise operators

后端 未结 16 1018
轮回少年
轮回少年 2020-12-08 20:01

I can check whether a number is odd/even using bitwise operators. Can I check whether a number is positive/zero/negative without using any conditional statements/operators l

16条回答
  •  醉酒成梦
    2020-12-08 20:22

    A simpler way to find out if a number is positive or negative: Let the number be x check if [x * (-1)] > x. if true x is negative else positive.

提交回复
热议问题