Unix Shell Script to convert between Big and Little Endian

Unix Shell Script to convert between Big and Little Endian

Post by Kennet » Wed, 08 Jun 2005 06:24:10



Hello,
   Can anyone post a shell script that can convert a binary file from
little to big Endian or vice versa? Or is there one that can do this? I
can use the 'dd' command line except that always flips every 2 bytes so
a 4 byte number wouldn't be converted right.

     Thank you,
     Kenneth

 
 
 

Unix Shell Script to convert between Big and Little Endian

Post by Kennet » Wed, 08 Jun 2005 06:26:09


Hello,
    Can anyone post a shell script that can convert a binary file from
little to big Endian or vice versa? Or is there one that can do this? I
can use the 'dd' command line except that always flips every 2 bytes so
a 4 byte number wouldn't be converted right.

    Thank you,
    Kennth

 
 
 

Unix Shell Script to convert between Big and Little Endian

Post by Kennet » Wed, 08 Jun 2005 06:26:15


Hello,
    Can anyone post a shell script that can convert a binary file from
little to big Endian or vice versa? Or is there one that can do this? I
can use the 'dd' command line except that always flips every 2 bytes so
a 4 byte number wouldn't be converted right.

    Thank you,
    Kennth

 
 
 

Unix Shell Script to convert between Big and Little Endian

Post by Kennet » Wed, 08 Jun 2005 06:26:17


Hello,
    Can anyone post a shell script that can convert a binary file from
little to big Endian or vice versa? Or is there one that can do this? I
can use the 'dd' command line except that always flips every 2 bytes so
a 4 byte number wouldn't be converted right.

    Thank you,
    Kennth

 
 
 

Unix Shell Script to convert between Big and Little Endian

Post by Darren Dunha » Wed, 08 Jun 2005 07:46:44



> Hello,
>    Can anyone post a shell script that can convert a binary file from
> little to big Endian or vice versa?

Only if you can exactly define what your data is.

 Or is there one that can do this? I

Quote:> can use the 'dd' command line except that always flips every 2 bytes so
> a 4 byte number wouldn't be converted right.

Do you have 2 byte numbers or 4 byte numbers (or 8 byte numbers)?  A
program can't just look at the binary file and guess...

--

Senior Technical Consultant         TAOS            http://www.taos.com/
Got some Dr Pepper?                           San Francisco, CA bay area
         < This line left intentionally blank to confuse you. >

 
 
 

Unix Shell Script to convert between Big and Little Endian

Post by Kennet » Wed, 08 Jun 2005 08:06:47


I heard it was impossible to swap a 4 byte number in a shell script
even if they are all 4 byte numbers.  Is there a way for the program in
a shell script to know if it is 2 or 4 byte, like look for whitespace?
 
 
 

Unix Shell Script to convert between Big and Little Endian

Post by Darren Dunha » Wed, 08 Jun 2005 09:19:58



> I heard it was impossible to swap a 4 byte number in a shell script
> even if they are all 4 byte numbers.

I don't know about impossible, but I'd probably prefer to do it in a
perl script.  That would handle binary data easily.

read, unpack, pack, print...

Quote:> Is there a way for the program in
> a shell script to know if it is 2 or 4 byte, like look for whitespace?

What whitespace?  Is this a file you know something about or are you
talking about an arbitrary binary file?  Such a file may not have
whitespace, or worse you might misinterpret binary data as whitespace.

Do you have a spec for the format, or is it something you're familiar
with?

--

Senior Technical Consultant         TAOS            http://www.taos.com/
Got some Dr Pepper?                           San Francisco, CA bay area
         < This line left intentionally blank to confuse you. >

 
 
 

Unix Shell Script to convert between Big and Little Endian

Post by Kennet » Thu, 09 Jun 2005 05:52:04


Pack/Unpack for Perl seem to work.  Thx.
Someone also mentioned Bit::Vector has a built-in function to reverse
bytes.  What is the built-in function or specific way on how to use it?
 
 
 

Unix Shell Script to convert between Big and Little Endian

Post by Kennet » Thu, 09 Jun 2005 05:59:11


Actually, it might be built-in though I never used the Bit::Vector
module before.
 
 
 

Unix Shell Script to convert between Big and Little Endian

Post by Darren Dunha » Fri, 10 Jun 2005 01:43:46



> Pack/Unpack for Perl seem to work.  Thx.
> Someone also mentioned Bit::Vector has a built-in function to reverse
> bytes.  What is the built-in function or specific way on how to use

it?

Bit::Vector isn't a standard module, so I'm not sure how "built-in"
comes into play here.

You can download it or read the docs for it on CPAN.

--

Senior Technical Consultant         TAOS            http://www.taos.com/
Got some Dr Pepper?                           San Francisco, CA bay area
         < This line left intentionally blank to confuse you. >

 
 
 

1. Unix Shell Script converter between Big and Little Endian

Hello,
    Can anyone post a shell script that can convert a binary file from
little to big Endian or vice versa? Or is there one that can do this? I
can use the 'dd' command line except that always flips every 2 bytes so
a 4 byte number wouldn't be converted right.

    Thank you,
    John

2. Printing in Unix

3. Little Endian vs. Big Endian (DOS/LINUX vs. Sun's Unix)

4. "source-ing" files in scripts

5. BIG ENDIAN ---> LITTLE ENDIAN

6. Q: *.mp3 files?

7. Solaris <-> Linux, Big Endian vs. Little Endian

8. WTB: Televideo 905 terminals

9. bit-fields, big endian --> little endian

10. - Big Endian / Little Endian - Code

11. Big Endian/Little Endian

12. Little endian Cramfs on big endian machines?

13. little endian to big endian