I've seen some pieces of code which use bitwise operations in order to create options/flags.
For example, consider the following examples from the ssl library:
# bitwise AND and NOT
ctx = ssl.create_default_context(Purpose.CLIENT_AUTH)
ctx.options &= ~ssl.OP_NO_SSLv3
# bitwise OR
client_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
client_context.options |= ssl.OP_NO_TLSv1
client_context.options |= ssl.OP_NO_TLSv1_1
The number values of these flags:
>>> ssl.OP_NO_SSLv3.value
33554432
>>> ssl.OP_NO_TLSv1.value
67108864
>>> ssl.OP_NO_TLSv1_1.value
268435456
I don't understand how this kind of system for creating flags works, or how those numbers were chosen. I've researched how the operators work, but I'm still confused.
Can someone please shine some light on how this works, and the appropriate use case?