N
nightolo
Hi all,
after all I have to say that I'm not a native english speaker so I pray
you to excuse for my poor english.
I got a trouble writing an application in a powerpc enviroment, that's
the problem:
A long time ago I studied that in powerpc we have got a big-endian
rappresentation and in x86 we got a little-endian.
For example an int like 0x2122 will be 0x00002122 in ppc (big-endian)
and 0x22210000 in x86 (little-endian). I think that's this theory is
right, I tested it with this code:
int main()
{
int i=0x11223344, e=0;
char *p;
for(e=0; e != 4; e++) {
p=(void *)&i+e;
printf("-%x- ",*p);
}
printf("\n");
return 0;
}
It obviously print different value in a powerpc or x86 arch, like
theory says.
So, if I write this piece of code on a x86:
int tmp;
tmp = 0x2122;
printf("casted tmp = %x\n" (unsigned char) tmp);
it returns 0x22, that seems ok, because 22 is the first byte in memory
(little-endian order).
But if I write the same code and compile it on powerpc arch I get the
*same* value!! it's strange, I should get 0x21, shouldn't I?
I don't know, manual says that htons and htonl point to a null macros
and that's ok, we don't need to convert a big-endian into a big-endian,
but with a cast I get this strange behaviour.. probably I mistake in
theory, expecially about a cast..
Any suggestion?
Thanks in advance,
Antonio
after all I have to say that I'm not a native english speaker so I pray
you to excuse for my poor english.
I got a trouble writing an application in a powerpc enviroment, that's
the problem:
A long time ago I studied that in powerpc we have got a big-endian
rappresentation and in x86 we got a little-endian.
For example an int like 0x2122 will be 0x00002122 in ppc (big-endian)
and 0x22210000 in x86 (little-endian). I think that's this theory is
right, I tested it with this code:
int main()
{
int i=0x11223344, e=0;
char *p;
for(e=0; e != 4; e++) {
p=(void *)&i+e;
printf("-%x- ",*p);
}
printf("\n");
return 0;
}
It obviously print different value in a powerpc or x86 arch, like
theory says.
So, if I write this piece of code on a x86:
int tmp;
tmp = 0x2122;
printf("casted tmp = %x\n" (unsigned char) tmp);
it returns 0x22, that seems ok, because 22 is the first byte in memory
(little-endian order).
But if I write the same code and compile it on powerpc arch I get the
*same* value!! it's strange, I should get 0x21, shouldn't I?
I don't know, manual says that htons and htonl point to a null macros
and that's ok, we don't need to convert a big-endian into a big-endian,
but with a cast I get this strange behaviour.. probably I mistake in
theory, expecially about a cast..
Any suggestion?
Thanks in advance,
Antonio