Created
April 14, 2023 07:00
-
-
Save andycasey/ff9ebf251bb80ee9ebfe23161ee48a0b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cartons = [ | |
SimplifiedCarton.create(id=5, carton="star"), | |
SimplifiedCarton.create(id=8, carton="galaxy") | |
] | |
source = Source.create(ra=0, dec=0) | |
source.carton_flags.set_bit(5) # add to star | |
source.carton_flags.set_bit(8) # add to galaxy | |
print(source.carton_flags) | |
# > bytearray(b' \x01') | |
print(int.from_bytes(source.carton_flags._buffer, byteorder='little')) | |
# > 288 | |
assert (2**5 + 2**8) == 288 | |
# Each byte can store up to 8 bits, so this one should be length 2 because the galaxy just pushes us over | |
assert len(source.carton_flags._buffer) == 2 | |
# Let's add a big carton | |
ufo = SimplifiedCarton.create(id=501, carton="UFO") | |
source.carton_flags.set_bit(ufo.id) | |
print(source.carton_flags._buffer) | |
# > 63 | |
print(source.carton_flags._buffer) | |
# > bytearray(b' \x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 ') | |
print(int.from_bytes(source.carton_flags._buffer, byteorder='little')) | |
# > 6546781215792283740026379393655198304433284092086129578966582736192267592809349109766540184651808314301773368255120142018434513091770786106657055179040 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment