B
bush
hi folks
I am new to this group.i need to know how i can find the endianness of
my system.help me out.
I am new to this group.i need to know how i can find the endianness of
my system.help me out.
bush said:hi folks
I am new to this group.i need to know how i can find the endianness of
my system.help me out.
#include <stdio.h>bush said:hi folks
I am new to this group.i need to know how i can find the endianness of
my system.help me out.
#include <stdio.h>bush said:hi folks
I am new to this group.i need to know how i can find the endianness of
my system.help me out.
The best way is not to ask the question in the first place.
Write code that doesn't care about endianness -- more generally,
that cares only about the values and not about how they are
represented.
Felix said:That's fine, if your code is C, and C alone. However, for performance
reasons, it is sometimes convenient to invoke assembly language functions
- and then, taking endianness into account matters.
That's fine, if your code is C, and C alone. However, for performance
reasons, it is sometimes convenient to invoke assembly language functions
- and then, taking endianness into account matters.
int n = 0x04030201;
char *s = (char *)&n;
printf("%d%d%d%d\n", s[0], s[1], s[2], s[3]);
return 0;
}
This will print '4321' on a big-endian system, like a mac G5 or a SUN
SPARC. On a pc it will print '1234', meaning it's little-endian. You
Only if you make it 'long'; PDP-11 'int' was 16 bits (2 bytes of 8).can of course simplify this into only two bytes if you like, it's just
what I had floating around on my disk. Depends on what you're using it
for, because then you can't see if it's a 'middle-endian' cpu (on a
PDP-11 it should print '3412', but those are rare anyway.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.