What is the best approach for determining a bit is on or off and managing something like this in Java? So if bit 1 is on I need to indicate the High outside temp alarm went active. Is this something I would use a collection or ENUM for? Being still new to Java trying to figure out how to do it right or best.
Thanks for the responses and the example. I have not done this kind of thing in C or Assembler. Twiddling bits has not been easy for me so I am learning as I go. I am Googling references on this type of approach to better understand what is going on.
Look at this, which confirms Henry's suspicion.
Henry Wong wrote:I think the comparison operator has higher precedence than the bitwise AND.
Rob Prime wrote:That's still my biggest weakness - I can never remember some of the precedence rules. Fortunately the compiler helps me out in those cases.
I don't even bother anymore... working in many languages simultaneously, some with slightly different precedence rules, it is just easier to add parens to everything.
And worse, while this would have been caught by the Java compiler, it wouldn't have by the C++ compiler.
Mike Bates wrote:
Twiddling bits has not been easy for me so I am learning as I go. I am Googling references on this type of approach to better understand what is going on.
Bit fiddling is described in The Java Programming Language by Gossling and others. You're not a real Java programmer until you have this book.