JPG segment length encoding
- by Blorgbeard
I'm trying to write some code to extract Exif information from a JPG.
Exif is stored in the APP1 segment of a JPG file. According to the Exif spec, the format of the APP1 segment is supposed to start like this:
FF E1 // APP1 segment marker
nn nn // Length of segment
45 // 'E'
78 // 'x'
69 // 'i'
66 // 'f'
And it goes until there is an FF followed by something other than FF or 00.
Looking at a JPG in a hex editor, I can see FF E1 and the Exif string, but I'm having trouble decoding the length bytes. An example: In one jpg, my hex editor tells me the APP1 segment is 686 bytes long, but the length bytes are F7 C8.
How should I use those bytes to come up with 686 decimal?