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?

2
  • Doesn't this depends on the file format?
    – caliban
    Sep 7, 2009 at 10:13
  • what i'm getting at is i don't think the file format matters for the tiff header...i think it's consistent and file format only has effect when describing the raw image data.
    – Tony Stark
    Sep 7, 2009 at 11:18

1 Answer 1

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.

4
  • so just to clarify: 0x08000400 in a file in little endian should be read as 0x00040008 in the real world, which is 262152 in decimal, right? also, in this example, would this number be a 32-bit number (4 hex pairs...)?
    – Tony Stark
    Sep 7, 2009 at 11:16
  • 1
    @hatorade, please note 0x08000400 is different from 0x08 0x00 0x04 0x00. The first is a 32-bit word and comes with endian-ness assumptions, the second is an byte-sequence where endian-ness is not relevant.
    – nik
    Sep 7, 2009 at 11:47
  • @nik: does 08:00 translate to 0x08 0x00 or 0x0800? I meant it to be the latter. I can edit my post if necessary.
    – Tony Stark
    Sep 7, 2009 at 12:02
  • 1
    I expect the ':' separators to imply a byte-sequence (with the endianness resolved). Also referred as an "octet stream".
    – nik
    Sep 7, 2009 at 12:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .