[TriLUG] OT: network byte order double swapping

Brian Weaver cmdrclueless at gmail.com
Mon Apr 4 12:20:23 EDT 2005


Since a 'double' and a 'long long' are both the same number of bytes.
You could do something like:

unsigned long long htonll(unsigned long long in)
{
    register unsigned long hold;
    register unsigned long *p = (unsigned long *)∈
    register unsigned long *q = p + 1;

    *p = htonl(*p);
    *q = htonl(*q);
    hold = *p;
    *p = *q;
    *q = hold;

    return in;
}


On Apr 4, 2005 12:10 PM, Charles Fischer <fischer at 4pi.com> wrote:
> I mean reorder 8 bytes as in a C 'double' type.  I am a bit concerned that
> the exponent and the mantissa may be in a different order as well as a byte
> order difference.  I am going from a Mac running OS10 to a Intel box
> running Fedora Core 3.
> 
> Thanks
> Charles
> 
> At 11:33 AM 4/4/2005, you wrote:
> >Do you mean a 2 bytes, as in a C 'short'? htons() perhaps. Or do you
> >mean that you need to reorder 8 bytes as in a C 'double' type?
> >
> >-Weave
> >
> >On Apr 4, 2005 11:18 AM, Charles Fischer <fischer at 4pi.com> wrote:
> > > I am looking for htond.  I need to do a double network byte order to a
> > > Intel double byte order in C on a Fedora Core 3 system.  Any ideas.
> > >
> > > Thanks
> > > Charles Fischer
> > >
> > > --
> > > TriLUG mailing list        : http://www.trilug.org/mailman/listinfo/trilug
> > > TriLUG Organizational FAQ  : http://trilug.org/faq/
> > > TriLUG Member Services FAQ : http://members.trilug.org/services_faq/
> > > TriLUG PGP Keyring         : http://trilug.org/~chrish/trilug.asc
> > >
> >--
> >TriLUG mailing list        : http://www.trilug.org/mailman/listinfo/trilug
> >TriLUG Organizational FAQ  : http://trilug.org/faq/
> >TriLUG Member Services FAQ : http://members.trilug.org/services_faq/
> >TriLUG PGP Keyring         : http://trilug.org/~chrish/trilug.asc
> 
> --
> TriLUG mailing list        : http://www.trilug.org/mailman/listinfo/trilug
> TriLUG Organizational FAQ  : http://trilug.org/faq/
> TriLUG Member Services FAQ : http://members.trilug.org/services_faq/
> TriLUG PGP Keyring         : http://trilug.org/~chrish/trilug.asc
>



More information about the TriLUG mailing list