Hex binary flags combination

Which of the following values ​​returns 63 as long as possible (in Java) and how?

0x0
0x1
0x2
0x4
0x8
0x10
0x20

I work with the NetworkManager API checkboxes if that helps. I get 63 from one of the operations, but I don’t know how to match the return value with the description.

thank

+3
source share
3 answers

63 is 32 | 16 | 8 | 4 | 2 | 1, where |is binary or operator.

Or in other words (in hexadecimal): 63 (0x3F) - 0x20 | 0x10 | 0x8 | 0x4 | 0x2 | 0x1. If you look at them all in binary format, this is obvious:

0x20 : 00100000
0x10 : 00010000
0x08 : 00001000
0x04 : 00000100
0x02 : 00000010
0x01 : 00000001

And 63:

0x3F : 00111111

If you get some return status and want to know what this means, you will have to use the binary and. For instance:

if (status & 0x02) 
{
}

, 0x02 ( ). (), - :

if (status & CONNECT_ERROR_FLAG)
{
}

, :

// Check if both flags are set in the status
if (status & (CONNECT_ERROR_FLAG | WRONG_IP_FLAG))
{
}

P.S.: , , this .

+18

, : 0x63 , ( 0x0).

, , - . , , . -, :

   0x01           0x02           0x04        ...        0x20
    |              |              |                      |
    |              |              |                      |
    V              V              V                      V
0000 0001      0000 0010      0000 0100      ...     0010 0000

, 63, 0x3F (= 3 * 16 1 + F * 16 0 F= 15) :

   0x3F
    |
    |
    V
0011 1111

, 6 , "" ( ) .

+2

63 (decimal) is 0x3F (hex). So 63 is a combination of all of the following flags:

0x20
0x10
0x08
0x04
0x02
0x01

Is this what you were looking for?

+1
source

Source: https://habr.com/ru/post/1727850/


All Articles