2

Let's say I open a tiff file in emacs and see the following in hexl-mode:

0x08000400

and I know the file is little endian. Does that mean the number is actually 262152 in decimal, or

0x00040008 

in hex? Would this conversion to a decimal number be different if it was 8-bit vs 16-bit?

phuclv
  • 30,396
  • 15
  • 136
  • 260
Tony Stark
  • 2,470

1 Answers1

2

For 8-bit values endian-ness does not matter.
Beyond that, the data structure of the field is important.

If you are working with a little endian file as a byte stream (like you show here),
a 16-bit value has its lower byte before its higher byte. So, "0x08 0x00" is the value 8.

Also, you might already know this, but its good to note.
From the Wikipedia TIFF page,

Every TIFF begins with a 2-byte indicator of byte order:
"II" for little endian and "MM" for big endian byte ordering.
The next 2 bytes represent the number 42,
selected because this is the binary pattern 101010 and
"for its deep philosophical significance".

The 42-reading depends upon the byte order indicated by the 2-byte indicator.
All words, double words, etc., in the TIFF file are read based per the indicated byte order.

The TIFF 6.0 specification says that compliant TIFF readers must support both byte orders (II and MM), however, TIFF writers may choose the byte order convenient for their image. This gave rise to the image-processing community's joke that TIFF is an acronym for Thousands of Incompatible File Formats.

nik
  • 57,042