Created
April 21, 2023 23:16
-
-
Save Aviksaikat/3ae5650191b106d7be30cad399029b98 to your computer and use it in GitHub Desktop.
Convert ethereum address to uint16
This file contains hidden or 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/python3 | |
def convert(ethereum_address="0x233d4E26853B3A7b8157bbd9F41f280A0f1cEe9B"): | |
# ethereum_address = "0x233d4E26853B3A7b8157bbd9F41f280A0f1cEe9B" | |
# 61083 | |
# Remove '0x' prefix and convert the address to bytes | |
address_bytes = bytes.fromhex(ethereum_address[2:]) | |
# Convert the address bytes to an integer | |
address_int = int.from_bytes(address_bytes, byteorder="big", signed=False) | |
# Map the Ethereum address to a uint16 value using modulo arithmetic | |
uint16_value = address_int % (2**16) | |
print(uint16_value) | |
if __name__ == "__main__": | |
convert("0x233d4E26853B3A7b8157bbd9F41f280A0f1cEe9B") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment