Using a bitwise & inside an if statement

╄→尐↘猪︶ㄣ 提交于 2019-12-01 03:42:06

Any of the following should work for you:

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

In C an integer expression can be used implicitly as a boolean expression (although I would argue that it is a bad idea), where zero is false and any non-zero value is true.

In Java that is not allowed so you have to make the expression explicitly boolean by comparing the integer result to some other integer value or expression using a comparison operator.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!