[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Enhancement request for od, dd

From: Jon Clifton
Subject: RE: Enhancement request for od, dd
Date: Mon, 10 Apr 2006 07:47:40 -0400


The case where endianness matters is -tfF which was the point I was trying to 
make. I agree that as a first look -tx1 will work fine to guess the layout and 
type of the data.


-----Original Message-----
From: Bob Proulx [mailto:address@hidden
Sent: Friday, April 07, 2006 6:51 PM
To: Jon Clifton
Cc: address@hidden
Subject: Re: Enhancement request for od, dd

Jon Clifton wrote:
> Bob Proulx wrote:
> > Please try using it with -tx1 and look at the output.  Is that
> > acceptable?  That should generate the same output on either big or
> > little endian machines.
> I failed to make my point clear. I was trying to see the data as
> float or double and they are just garbage without appropriate
> byteswapping.

Now I really don't understand.  Why is one just garbage and another is
not?  Let me show you an example of what I am talking about.

  printf "abcdefgh\n" | od -tx1
  0000000 61 62 63 64 65 66 67 68 0a

  printf "abcdefgh\n" | od -tx
  0000000 61626364 65666768 0a000000

Gosh, the difference seems negligible to me.  Why would you say that
the first one is garbage but the second one is not?

Of course on a big endian machine the ordering of bytes is different
for the native word case.

  printf "abcdefgh\n" | od -tx1
  0000000 61 62 63 64 65 66 67 68 0a

  printf "abcdefgh\n" | od -tx
  0000000 64636261 68676665 0000000a

This is why I suggest avoiding the native word case and to always
specify -tx1 to get byte ordering.  It avoids that problem entirely.

If you wanted to group bytes together you could do some simple text
processing to get rid of the extra spaces.  This is a little
cumbersome but just for illustration this is off the top of my head.
It is not quite general purpose when used with the z option.  Oh well.

  printf "abcdefghijklmno\n" | od -tx1z | sed ':top;s/ /_/;s/ //;s/ //;s/ 
//;ttop;s/_/ /g'
  0000000 61626364 65666768 696a6b6c 6d6e6f0a >abcdefghijklmno.<

> I think the dd option "swab" is only for PDP-11 type data. It isn't
> the correct format for Intel i386 and I can't remember if the bytes
> in a double end up 87654321 or 43218765 on Intel.

  printf "abcdefgh\n" | dd conv=swab | od -tx
  0000000 63646162 67686566 0000000a

Ah, I see that it swaps bytes along two byte boundaries and not along
four byte boundaries.  I see discussion of this just recently which I
had previously missed.
And I might as well mention this for the archive.  Similar to your C
program but on the command line.

  printf "abcdefghijklmno\n" \
  | perl -e 'while (sysread(STDIN,$d,4)){print pack("N",unpack("V",$d));}' \
  | od -tx
  0000000 61626364 65666768 696a6b6c 6d6e6f0a


reply via email to

[Prev in Thread] Current Thread [Next in Thread]