This is some code which prints a hexdump of a list of 16 bit numbers, at 16 bytes distance for each, after the "print data" comment:
#!/usr/bin/python3
# creating test data
data = []
for i in range(500):
data = data + [ i & 0xff, i >> 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
# print data
c = 0
out = ""
for i in range(int(len(data) / 16)):
if i == 512: break
low = data[i * 16]
high = data[i * 16 + 1]
d = low | (high << 8)
out = out + ("%04x " % d)
if (i % 16) == 15: out = out + "\n"
print(out)
It works, but I think I can write it simpler with "join" and maybe list comprehension? But shouldn't be a cryptic one-liner or something, I'm just looking for a more idiomatic Python solution. I want to print the first 512 numbers, but the data array can be shorter or longer.