forked from mirror/Archipelago
Some checks failed
Analyze modified files / flake8 (push) Failing after 2m28s
Build / build-win (push) Has been cancelled
Build / build-ubuntu2204 (push) Has been cancelled
ctest / Test C++ ubuntu-latest (push) Has been cancelled
ctest / Test C++ windows-latest (push) Has been cancelled
Analyze modified files / mypy (push) Has been cancelled
Build and Publish Docker Images / Push Docker image to Docker Hub (push) Successful in 5m4s
Native Code Static Analysis / scan-build (push) Failing after 5m2s
type check / pyright (push) Successful in 1m7s
unittests / Test Python 3.11.2 ubuntu-latest (push) Failing after 16m23s
unittests / Test Python 3.12 ubuntu-latest (push) Failing after 28m19s
unittests / Test Python 3.13 ubuntu-latest (push) Failing after 14m49s
unittests / Test hosting with 3.13 on ubuntu-latest (push) Successful in 5m0s
unittests / Test Python 3.13 macos-latest (push) Has been cancelled
unittests / Test Python 3.11 windows-latest (push) Has been cancelled
unittests / Test Python 3.13 windows-latest (push) Has been cancelled
37 lines
943 B
Python
37 lines
943 B
Python
def extract_bits(input_byte, input_offset):
|
|
bit_list = []
|
|
temp = get_bitflag(input_byte)
|
|
|
|
for x in range(0, len(temp)):
|
|
if temp[x] == "1":
|
|
bit_list.append(((input_offset + 1) * 8) - int(x+1))
|
|
|
|
return bit_list
|
|
|
|
|
|
def get_bitflag(input_byte):
|
|
input_byte = change_endian(input_byte)
|
|
temp = str(bin(input_byte))
|
|
temp = str.removeprefix(temp, "0b")
|
|
while len(temp) < 8:
|
|
temp = "0" + temp
|
|
return temp
|
|
|
|
|
|
def bit_flagger(input_byte, flag_position, bool_setting):
|
|
if bool_setting:
|
|
bool_char = "1"
|
|
else:
|
|
bool_char = "0"
|
|
byte_string = get_bitflag(input_byte)
|
|
reverse_pos = len(byte_string) - flag_position
|
|
byte_string = byte_string[:reverse_pos-1] + bool_char + byte_string[reverse_pos:]
|
|
val = int(byte_string, 2)
|
|
return val
|
|
|
|
|
|
def change_endian(byte):
|
|
byte = int(byte)
|
|
byte = byte.to_bytes(2, "big")
|
|
return int.from_bytes(byte, "big")
|