Encodes the given bytes into base16. >>> base16_encode(b'Hello World!') '48656C6C6F20576F726C6421' >>> base16_encode(b'HELLO WORLD!') '48454C4C4F20574F524C4421' >>> base16_encode(b'') ''
(data: bytes)
| 1 | def base16_encode(data: bytes) -> str: |
| 2 | """ |
| 3 | Encodes the given bytes into base16. |
| 4 | |
| 5 | >>> base16_encode(b'Hello World!') |
| 6 | '48656C6C6F20576F726C6421' |
| 7 | >>> base16_encode(b'HELLO WORLD!') |
| 8 | '48454C4C4F20574F524C4421' |
| 9 | >>> base16_encode(b'') |
| 10 | '' |
| 11 | """ |
| 12 | # Turn the data into a list of integers (where each integer is a byte), |
| 13 | # Then turn each byte into its hexadecimal representation, make sure |
| 14 | # it is uppercase, and then join everything together and return it. |
| 15 | return "".join([hex(byte)[2:].zfill(2).upper() for byte in list(data)]) |
| 16 | |
| 17 | |
| 18 | def base16_decode(data: str) -> bytes: |
nothing calls this directly
no outgoing calls
no test coverage detected