MCPcopy Create free account
hub / github.com/PiLiDAR/PiLiDAR / hex_from_bytes

Function hex_from_bytes

lib/binary_utils.py:3–13  ·  view source on GitHub ↗

Return the hexadecimal representation of the binary data. Every byte of data is converted into the corresponding 2-digit hex representation. The resulting string is therefore twice as long as the length of data.

(byte_string, spaced=False)

Source from the content-addressed store, hash-verified

1import binascii
2
3def hex_from_bytes(byte_string, spaced=False):
4 """Return the hexadecimal representation of the binary data. Every byte of
5 data is converted into the corresponding 2-digit hex representation. The
6 resulting string is therefore twice as long as the length of data.
7 """
8 hex_string = binascii.hexlify(byte_string).decode('ascii')
9
10 if spaced:
11 hex_string = ' '.join([hex_string[i:i+2] for i in range(0, len(hex_string), 2)])
12
13 return hex_string
14
15def bytes_from_hex(hex_string, spaced=False):
16 """Return the binary data represented by the hexadecimal string. Every 2-digit hex representation

Callers 1

binary_utils.pyFile · 0.85

Calls 1

decodeMethod · 0.80

Tested by

no test coverage detected