Little Indian/Big Indian

Little Indian/Big Indian

Post by Sandeep Nirmal » Sat, 26 Jun 1999 04:00:00



Hi,

I have a file on Linux(little Indian m/c) and written
some long integer data in file. Now I get this file on solaris
(Big indian ) m/c (via binary ftp).
How can I get same data which I have entered on linux on
solaris m/c?

Basically I want how to convert little indian m/c file
to big indian m/c file and vice a versa.

Thanks,
Sandeep

 
 
 

Little Indian/Big Indian

Post by Andy Knigh » Sat, 26 Jun 1999 04:00:00



> Hi,

> I have a file on Linux(little Indian m/c) and written
> some long integer data in file. Now I get this file on solaris
> (Big indian ) m/c (via binary ftp).
> How can I get same data which I have entered on linux on
> solaris m/c?

> Basically I want how to convert little indian m/c file
> to big indian m/c file and vice a versa.

> Thanks,
> Sandeep

The best way to approach this problem is to store the data in a host
independent form. There are two complementary functions htonl() and
ntohl() which handle unsigned 32-bit data. These functions are typically
used for the transmission of data over a socket but can be used for the
purpose you describe. You would convert the data using htonl() before
writing the data into a file (or a socket) and use ntohl() to extract
the data. If the data have already been written in host (natural) form,
then you'll need to do some byte swapping on the big-endian system.

--
Andy Knight

You can call me a pedagogue if you like but I won't know what you're on
about!

 
 
 

Little Indian/Big Indian

Post by Rainer Temm » Sat, 26 Jun 1999 04:00:00



> Hi,

> I have a file on Linux(little Indian m/c) and written
> some long integer data in file. Now I get this file on solaris
> (Big indian ) m/c (via binary ftp).
> How can I get same data which I have entered on linux on
> solaris m/c?

> Basically I want how to convert little indian m/c file
> to big indian m/c file and vice a versa.

Hi Sandeep,

generally have a look at htonl() ntohl() htons() ntohs().
These are fine if they are use on both sides (before writing something to, or
reading something from a file).
These functions perform no action if they are called on a machine that
already uses the network-format internally.
In your case the file is already there, and you'll have to swap the integers explicitly.

For shorts: swap byte 0 with 1
For longs: swap byte 0 with 3 and byte 1 with 2
For floats: If both machines use IEEE same as long
For doubles: If both machines use IEEE: swap 0 w. 7  1 w. 6  2 w. 5 and 3 w. 4

Regards Rainer

 
 
 

Little Indian/Big Indian

Post by Tom Cowel » Sat, 26 Jun 1999 04:00:00


It might help you, while you are implementing a permanent fix, to know
that dd has a conv=swab option for changing the byte ordering in a file.

Tom Cowell

 
 
 

Little Indian/Big Indian

Post by Rainer Temm » Sat, 26 Jun 1999 04:00:00




> #
> # Hi,
> #
> # I have a file on Linux(little Indian m/c) and written
> # some long integer data in file. Now I get this file on solaris
> # (Big indian ) m/c (via binary ftp).
> # How can I get same data which I have entered on linux on
> # solaris m/c?
> #
> # Basically I want how to convert little indian m/c file
> # to big indian m/c file and vice a versa.

> Are Big Indian and Little Indian the names of machines or do you mean
> big endian and little endian? ;)

May be the machines names were 'Big Indian' and 'Little Indian' >>:-))
 
 
 

Little Indian/Big Indian

Post by Andrew Gabri » Sat, 26 Jun 1999 04:00:00





>#
># Hi,
>#
># I have a file on Linux(little Indian m/c) and written
># some long integer data in file. Now I get this file on solaris
># (Big indian ) m/c (via binary ftp).
># How can I get same data which I have entered on linux on
># solaris m/c?
>#
># Basically I want how to convert little indian m/c file
># to big indian m/c file and vice a versa.

>Are Big Indian and Little Indian the names of machines or do you mean
>big endian and little endian? ;)

The Solaris machine might prefer to be called Big Chief  :-)

--
Andrew Gabriel
Consultant Software Engineer

 
 
 

Little Indian/Big Indian

Post by Victor Wagn » Tue, 29 Jun 1999 04:00:00


: It might help you, while you are implementing a permanent fix, to know
: that dd has a conv=swab option for changing the byte ordering in a file.

but this doesn't help much if file contain anything but short ints.

There is also function swab in system library.

And probably, there is perl on your SUN machine. Read man perlfunc about
perl builtins pack and unpack. They can be very helpful in such a
situation. If there is no perl, there can be Tcl with its "binary scan"
and "binary format"

: Tom Cowell
--
--------------------------------------------------------

I don't answer questions by private E-Mail from this address.