okay...im kind of confused...
i am sitting here at work, kind of bored. I have finished all my work, so I decided to program for awhile just for fun.
But anyways, as most of us know, in a big endian machine, the most significant byte is stored lower in memory, so the integer FFFF would be stored as such in memory:
00 00 FF FF
In a little endian machine, the least significant byte is store lower in memory, and so that same number would be stored as such:
FF FF 00 00
Well, my machine here at work is a Win2k machine...running on an Intel processor, and therefore it is little endian because Intel processors are little endian. Or at least according to this website they are: http://www.netrino.com/Publications/...ndianness.html
Well, what confuses me is this. I outputted the unsigned integer FFFF bit by bit from left to right, and it came out like this:
00000000 00000000 11111111 11111111
All i did was bitshift and output in a loop. Well, since intel machines little endian, isnt that backwards? shouldnt it be outputting:
11111111 11111111 00000000 00000000
or am i just not thinking straight right now.....
maybe this should have gone on the tech board...i dunno...i just posted it here...but if it should be on the tech board feel free to move it there
Within the confines of a single program, endian-ess is pretty much a non issue. It does not matter to your program whether FFFF is stored as FFFF0000 or 0000FFFF, because it will always have the value FFFF. So when you output the bits, you get what you expect.
unsigned long foo = 0xFFFF;
fwrite( &foo, sizeof foo, 1, fp );
Take this file to another machine, one with a different endian and repeat your exercise. Then you'll see what endian means.
You're probably not doing the printing at the byte level. You should cast a pointer to the integer to unsigned char* and then print out the bytes in sequence.
"One little, two little, three little endians.."
Sorry, I had to.. :D
Endianness doesnt concern individual bits, it affects bytes as a whole. So when you print out the individual bits in order from 0 - 31 you will get them in that order no matter what the endian of the machine is. In the number 0x0001 for instance, 1 is always in bit position 0.