Rafael Espindola | 228290c | 2010-09-11 15:25:58 +0000 | [diff] [blame^] | 1 | def dataToHex(d): |
2 | """ Convert the raw data in 'd' to an hex string with a space every 4 bytes. | ||||
3 | """ | ||||
4 | bytes = [] | ||||
5 | for i,c in enumerate(d): | ||||
6 | byte = ord(c) | ||||
7 | hex_byte = hex(byte)[2:] | ||||
8 | if byte <= 0xf: | ||||
9 | hex_byte = '0' + hex_byte | ||||
10 | if i % 4 == 3: | ||||
11 | hex_byte += ' ' | ||||
12 | bytes.append(hex_byte) | ||||
13 | return ''.join(bytes).strip() |