Re: Unix Shell Script converter between Big and Little Endian
From: bsh (brian_hiles_at_rocketmail.com)
Date: 11 Jun 2005 17:40:22 -0700
Robert Bonomi wrote:
> bsh <firstname.lastname@example.org> wrote:
> >dd conv=swap if=infputfile of=outputfile conv=swab
> what does that do to a character string?
> what does that to to a 32-bit quantity?
> what does that do to a 64-bit quantity?
> what does that do to a 16-bit quantity that occurs _after_
> an odd-length length character string?
First of all, I correct my syntax by meaning "conv=swab",
not "conv=swap". An identical command line is apparently
at: http://www.asc.hpc.mil/overall/faq/o3kfaqs.php .
Well then, a quibble: the criterion of a _best_ solution should
be how few pages of documentation is taken to describe it ;) or
maybe the reason to use any given tool has to balanced against the
_real_ solutions provided exactly for them, but presumably not
Each of the above problems above can be adequately solved with
a suitable application (kludge?) of dd(1). What you are really
asking is, what is the criterion of using the special purpose
(XDR) or sophisticated (perl) tool versus the ubiquitous one
(dd)? And you are quite correct in you accessment that the
task is fraught with peril.
Coincidentally, a version of dd(1) provided with AST, and
presumable built in to ksh93 as a "special shell builtin"
has not only the canonical "conv=swab" option but another
"swap=" option that allows for all the options you express
above! Also, much can be simulated with the ibs, obs, block,
unblock, and sync option arguments.
"swap=number - Swap bytes acording to the inclusive or of:
1-byte, 2-short, 4-long, 8-quad, etc."
Beyond all this, the more one goes down the road of endedness
and data portability, the windier the road becomes.
Endian FAQ: http://www.rdrop.com/~cary/html/endian_faq.html
> Should I continue? <grin>
Of course you are right, but I had to level the field by
exhibitting the fact that I really did understand the esoteric
nuances and ramifications of the issue.