summaryrefslogtreecommitdiff
path: root/test/Scripts/common_dump.py
blob: 444b389dd0edd0071c701652f8f7a1fe270936f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
def dataToHex(d):
    """ Convert the raw data in 'd' to an hex string with a space every 4 bytes.
    """
    bytes = []
    for i,c in enumerate(d):
        byte = ord(c)
        hex_byte = hex(byte)[2:]
        if byte <= 0xf:
            hex_byte = '0' + hex_byte
        if i % 4 == 3:
            hex_byte += ' '
        bytes.append(hex_byte)
    return ''.join(bytes).strip()