bug-coreutils
[Top][All Lists]
Advanced

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

Re: Enhancement request for od, dd


From: Bob Proulx
Subject: Re: Enhancement request for od, dd
Date: Fri, 7 Apr 2006 16:50:48 -0600
User-agent: Mutt/1.5.9i

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

Bob




reply via email to

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