Hex combination of binary flags
hex, numbers
Solution
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:
0x20 : 00100000
0x10 : 00010000
0x08 : 00001000
0x04 : 00000100
0x02 : 00000010
0x01 : 00000001
And 63 is:
0x3F : 00111111
If you're getting some return status and want to know what it means, you'll have to use binary and. For example:
if (status & 0x02)
{
}
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:
if (status & CONNECT_ERROR_FLAG)
{
}
Again, the status can be a combination of stuff:
// Check if both flags are set in the status
if (status & (CONNECT_ERROR_FLAG | WRONG_IP_FLAG))
{
}
P.S.: To learn why this works, this is a nice article about binary flags and their combinations.
Problem
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