使用按位&安培; IF语句内 [英] Using a bitwise & inside an if statement
本文介绍了使用按位&安培; IF语句内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在C,我可以写一个if语句
In C, I can write an if-statement
if (firstInt & 1)
但是当我尝试做在Java中一样,编译器告诉我:不兼容的类型,并说我需要一个布尔
代替 INT
。有什么办法用Java编写的C code吗?
but when I try and do the same in Java, the compiler tells me "incompatible types" and says I need a boolean
instead of an int
. Is there any way to write that C code in Java?
推荐答案
凡有下列应为你工作:
if ((firstInt & 1) != 0)
if ((firstInt & 1) > 0)
if ((firstInt & 1) == 1)
这篇关于使用按位&安培; IF语句内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文