There are several benefits of using hexadecimal, such as:
It is easy to see the common characteristics of corresponding positions. For example, the first three digits of MODE_WORLD_READABLE and MODE_WORLD_WRITABLE in your screenshot are 0 (hexadecimal). If you use decimal numbers, this representation is not obvious
Using hexadecimal (which can quickly correspond to binary one-to-one), it is convenient to perform bit mask operations, such as shifting, or OR to calculate a combined identification flag.
My personal guess is to make bit operations more intuitive. A lot of bit operations are used in the Android source code. Compared with the decimal system, the hexadecimal system is more intuitive and easy to understand.
static final int FLAG_CLIP_CHILDREN = 0x1;
private static final int FLAG_CLIP_TO_PADDING = 0x2;
static final int FLAG_INVALIDATE_REQUIRED = 0x4;
private static final int FLAG_RUN_ANIMATION = 0x8;
static final int FLAG_ANIMATION_DONE = 0x10;
private static final int FLAG_PADDING_NOT_NULL = 0x20;
private static final int FLAG_ANIMATION_CACHE = 0x40;
static final int FLAG_OPTIMIZE_INVALIDATE = 0x80;
static final int FLAG_CLEAR_TRANSFORMATION = 0x100;
Then all the above attributes are marked together with an int variable mGroupFlags, and each bit records the status of an attribute (0 or 1)
Using hexadecimal is more intuitive and you can calculate it mentally directly
There are several benefits of using hexadecimal, such as:
It is easy to see the common characteristics of corresponding positions. For example, the first three digits of MODE_WORLD_READABLE and MODE_WORLD_WRITABLE in your screenshot are 0 (hexadecimal). If you use decimal numbers, this representation is not obvious
Using hexadecimal (which can quickly correspond to binary one-to-one), it is convenient to perform bit mask operations, such as shifting, or OR to calculate a combined identification flag.
stackoverflow portal: http://stackoverflow.com/questions/10920432/why-use-hexadecimal-consta...
My personal guess is to make bit operations more intuitive. A lot of bit operations are used in the Android source code. Compared with the decimal system, the hexadecimal system is more intuitive and easy to understand.
Take ViewGroup source code as an example:
Then all the above attributes are marked together with an int variable mGroupFlags, and each bit records the status of an attribute (0 or 1)
Using hexadecimal is more intuitive and you can calculate it mentally directly
If it is written in decimal, it will be more troublesome to calculate which digit represents which variable, and it looks very painful