Using a bitwise & inside an if statement

前端 未结 2 2000
名媛妹妹
名媛妹妹 2021-01-11 15:47

In C, I can write an if-statement

if (firstInt & 1)

but when I try and do the same in Java, the compiler tells me \"incompatible types\

2条回答
  •  囚心锁ツ
    2021-01-11 16:06

    Any of the following should work for you:

    if ((firstInt & 1) != 0)
    if ((firstInt & 1) > 0)
    if ((firstInt & 1) == 1)
    

提交回复
热议问题