Java: Checking if a bit is 0 or 1 in a long

前端 未结 14 1834
抹茶落季
抹茶落季 2020-11-29 01:14

What method would you use to determine if the the bit that represents 2^x is a 1 or 0 ?

14条回答
  •  一个人的身影
    2020-11-29 01:41

    I wonder if:

      if (((value >>> x) & 1) != 0) {
    
      }
    

    .. is better because it doesn't matter whether value is long or not, or if its worse because it's less obvious.

    Tom Hawtin - tackline Jul 7 at 14:16

提交回复
热议问题