1

I have a binary file containing 4-byte floats. I want to print these floats using od. However, od prints one additional value at the very first position. What is going on here?

The file looks like this:

xxd test | head -1

0000000: 932a 6541 7cdf 6b41 6c7e 7141 d779 7641 .*eA|.kAl~qA.yvA

od prints this:

cat test | od -f -An -v -w4 | head -2

   14,322894
   14,742062

The first printed value (14.32) is not the first value in the file. The second printed value (14.74) is the actual first value from the file. I verified with several hex editors that

932a 6541

is 14.74206 (or a value very close to that). So where is od getting the extra value (14.32) from? This also happens when all other options are omitted:

cat test | od -f | head -2

0000000 14,322894 14,742062 15,093365 15,404746

0000020 15,652825 15,938543 16,25734 16,616056

  • Can you give us access to one of your test files so we can see if we can reproduce the error? – terdon Mar 01 '16 at 10:36
  • @terdon: I'm afraid I can't since it is confidential. But I could reproduce it with the following small sample: echo 932a65417cdf6b416c7e7141 | xxd -r -p | od -f – Andreas Unterweger Mar 01 '16 at 10:41
  • 1
    Why do you believe that this is not the first value in the file? echo 932a6541 | xxd -r -p | od -f - gives just the number 1,4322894e+01 when using a POSIX compliant od. – schily Mar 01 '16 at 12:39
  • Wow, this is embarrassing. It seems that both hex editors that I tried don't format the float based on the selected four bytes, but on the next four bytes after the cursor. So this is clearly an error on my side. Sorry for the confusion and thanks for clarifying. – Andreas Unterweger Mar 01 '16 at 12:49

1 Answers1

0

od is correct. I based my expected output on two hex editors which showed a floating-point value other than the one I selected. Thank you, @schily, for pointing out that the first four bytes actually represent 14.32 and that od is therefore correct.