Which of the following give back 63 as long (in Java) and how?
0x0
0x1
0x2
0x4
0x8
0x10
0x20
I’m working with NetworkManager API flags if that helps. I’m getting 63 from one of the operations but don’t know how should I match the return value to the description.
Thanks
63 is
32 | 16 | 8 | 4 | 2 | 1, where|is the binary or operator.Or in other words (in hex): 63 (which is 0x3F) is
0x20 | 0x10 | 0x8 | 0x4 | 0x2 | 0x1. If you look at them all in binary, it is obvious:And 63 is:
If you’re getting some return status and want to know what it means, you’ll have to use binary and. For example:
Will execute if the flag 0x02 (that is, the 2nd bit from the right) is turned on in the returned status. Most often, these flags have names (descriptions), so the code above will read something like:
Again, the status can be a combination of stuff:
P.S.: To learn why this works, this is a nice article about binary flags and their combinations.