A handy sheet of decimal, hexadecimal and binary bitwise values for use in flags, settings when programming.
Hello,
When programming it's often useful to define a series of flags as "bitwise" values that can be combined (OR'd) together and then tested later via an AND type operation. Most programming languages support this behaviour and it can be a quick and efficient method of storing settings in a single integer.
It can however be tricky to remember of the top of your head all the hexadecimal or decimal values for the various bits once you get above about 65536 so here's a handy "cheat sheet" to provide the values that you can use in your code :
Decimal |
Hexadecimal |
24 bit binary |
1 |
0x000001 |
000000000000000000000001 |
2 |
0x000002 |
000000000000000000000010 |
4 |
0x000004 |
000000000000000000000100 |
8 |
0x000008 |
000000000000000000001000 |
16 |
0x000010 |
000000000000000000010000 |
32 |
0x000020 |
000000000000000000100000 |
64 |
0x000040 |
000000000000000001000000 |
128 |
0x000080 |
000000000000000010000000 |
256 |
0x000100 |
000000000000000100000000 |
512 |
0x000200 |
000000000000001000000000 |
1024 |
0x000400 |
000000000000010000000000 |
2048 |
0x000800 |
000000000000100000000000 |
4096 |
0x001000 |
000000000001000000000000 |
8192 |
0x002000 |
000000000010000000000000 |
16384 |
0x004000 |
000000000100000000000000 |
32768 |
0x008000 |
000000001000000000000000 |
65536 |
0x010000 |
000000010000000000000000 |
131072 |
0x020000 |
000000100000000000000000 |
262144 |
0x040000 |
000001000000000000000000 |
524288 |
0x080000 |
000010000000000000000000 |
1048576 |
0x100000 |
000100000000000000000000 |
2097152 |
0x200000 |
001000000000000000000000 |
4194304 |
0x400000 |
010000000000000000000000 |
8388608 |
0x800000 |
100000000000000000000000 |
Happy coding!
Comments (0)
Add a Comment
Please login to comment.