Jun 24, 2009, 11:42 PM
Post #1 of 2
reading binary data and writing it as hex
I have a binary data file: 43 2F FF A2 2B 12 99 4C... (each pair represents a byte)
The user is supposed to give me a pattern: 0000_###_0 (each '#' represents a byte)
And I want to ouput:
The pattern isn't fixed, so the number of '#' may change (though they have to be consecutive).
Let's say I already read the amount of bytes requestsed from the data file, is there a way to use 'unpack' to output such a hex number (which isn't the size of an int or long necessarily)?
BTW, I could do it by writing one byte at a time but the data files I'm dealing with are very big and I'm looking for a faster way to do it... (specifically to unpack into a variable and writing it with printf and %x).
Thanks a lot!