So I’ve got this simple code in C.
if (flags & 4)
Now when I port the line to java:
if ((flags & 4) == 1)
It doesn’t trigger. Whats the correct way to port the C code to Java? What am I doing wrong with the & operator?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It should be
!= 0rather than== 1:The reason for this is that in C anything that is not zero is considered
truein anifstatement, while Java forces you to use Booleans. In this case, the expression can evaluate either to 4 or to 0, so comparing it with 1 is always false.