Created
June 24, 2020 08:51
-
-
Save jasperla/e7f0221d6f37b0c6e53d51560d8a5dea 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
#!/usr/bin/env python3 | |
badbytes = b'\x00\x0a\x0d\x0f\x14\x15\x5c\x2f\x3a\xff' | |
print(f'badbytes raw = {badbytes}') | |
print('individual bad bytes as hex = ', end='') | |
[print(hex(x), end=' ') for x in badbytes] | |
print() | |
# Declare block explicitly as bytes: | |
block = b'\xfe\x5a\x05\x3c' | |
# Using 'big' endianness here to ensure the bytes stay in the provided order. | |
block_dec = int.from_bytes(block, 'big') | |
block_hex = hex(block_dec) | |
print(f'Provided block raw = {block} as a number = {block_dec} or as hex = {block_hex}') | |
first_byte = block[0] | |
print(f'first_byte = {block[0]} and as hex: {hex(block[0])}') | |
# The int() is required as '/' returns a 'float' | |
print(f'Half of first byte: {block[0] / 2} and as hex: {hex(int(block[0]/2))}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment