Java – use bitwise and in if statements

In C, I can write an IF statement

if (firstInt & 1)

But when I try to perform the same operation in Java, the compiler will tell me "incompatible types" and say that I need a Boolean value instead of an int. is there any way to write c code in Java?

Solution

Any of the following applies to you:

if ((firstInt & 1) != 0)
if ((firstInt & 1) > 0)
if ((firstInt & 1) == 1)
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>