ts-7000
[Top] [All Lists]

Re: [ts-7000] size and byte order of ints

To:
Subject: Re: [ts-7000] size and byte order of ints
From: Markus Peuhkuri <>
Date: Wed, 13 Sep 2006 21:17:06 +0300
Don W. Carr wrote:
> > On the question of 64 bit integers, does anybody know if there is a
> > standard routine to convert to network byte order?

I do not know if there is a standard, but I've used following on
little-endian system, and for bigendian the macros are null (#define
ntohll(X) (X)).

static inline unsigned long long
__swapll(unsigned long long ull) {
        return ((ull & 0xff00000000000000LL) >> 56) |
            ((ull & 0x00ff000000000000LL) >> 40) |
            ((ull & 0x0000ff0000000000LL) >> 24) |
            ((ull & 0x000000ff00000000LL) >> 8) |
            ((ull & 0x00000000ff000000LL) << 8) |
            ((ull & 0x0000000000ff0000LL) << 24) |
            ((ull & 0x000000000000ff00LL) << 40) |
            ((ull & 0x00000000000000ffLL) << 56);
}
#define ntohll(X) __swapll(X)
#define htonll(X) __swapll(X)


To check endianess, you can use perl too:
perl -e 'print pack('I', 0x01020304)' | od -t x1

If you get "04 03 02 01", then you have little-endian system.

Yan Seiner wrote:
> > I need to allocate 16, 32, and 64 unsigned ints, and I don't know if
> > such animals exist on the arm....

Use standard C types, int16_t, uint32_t if you want to make portable code.

> > Also, I've read that the arm can be both big-endian and little-endian.
> >  How does one go about determining which variant we have?  Or is it
> > software-set?

With C code you can use:

main() {
uint32_t v = 0x01020304;
write(1,&v; sizeof(uint_32_t))
}

./a.out | od -t x1

ps. seems that my messages to the list disapperar without trace...

Markus | http://www.iki.fi/puhuri/


 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/ts-7000/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/ts-7000/join
    (Yahoo! ID required)

<*> To change settings via email:
     
    

<*> To unsubscribe from this group, send an email to:
    

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



<Prev in Thread] Current Thread [Next in Thread>
Admin

Disclaimer: Neither Andrew Taylor nor the University of NSW School of Computer and Engineering take any responsibility for the contents of this archive. It is purely a compilation of material sent by many people to the birding-aus mailing list. It has not been checked for accuracy nor its content verified in any way. If you wish to get material removed from the archive or have other queries about the archive e-mail Andrew Taylor at this address: andrewt@cse.unsw.EDU.AU