Quote Originally Posted by freedompeace View Post


Well the contest hasn't started yet (doesn't until the weekend), I just have a feeling that something like this will probably be on it. After all I'm going to be dominated by people of your caliber

I've always assumed it was little-endian (since it was easier), but if it was big-endian, the same series: 0000 0000 0000 0000 1000 0000 0000 0001 to a short would be:

reverse byte order = 0000 0001 1000 0000 0000 0000 0000 0000
to sizeof short = 0000 0000 0000 0000
= 0?

-------------------------------

Taking a more "complex" example: 0000 0011 0100 1111 1000 1000 0000 0001
reverse byte order = 0000 0001 1000 1000 0100 1111 0000 0011
to sizeof short: 0100 1111 0000 0011
complement: 1011 0000 1111 1100
subtract 1 = 1011 0000 1111 1011
= 12539?

I'm not sure about these ones, so any help would be awesome C:

(More verbose than it needs to be, but in case I fuck up, it'll (hopefully) be easier to see where I went wrong)
Probably easier when just looking at the bytes vs bit level:

Taking your first post sample of the 2097217:
Hex (32 bit) this would be 00 20 00 41, written in memory in LE as: 41 00 20 00. If you imagine a pointer pointing to the first memory address, and the 'type' of pointer telling you how many bytes you'll be reading (short =2, int =4, char/byte=1) then obviously casting to a short will give you 41 00 (which is 0x0041 after flipping the bytes back in order) or a char of 0x41 since the first memory address stays the same. Big-Endian would store the number as is: 00 20 00 41, and would be pointing at the 0x00 which is now the first memory location, so you start casting to a short you end up with 0x0020 , or a char/byte would be 0x00


Your sample above (if I converted it right) in hex is: 0x03 4f 88 01; so casting to a short is simply 0x03 4F on a Big-Endian system and would be 0x 88 01 on a Little Endian System (stored as 01 88 4F 03, thus points to 01 88, which when read, reads as 0x8801)

Big-Endian is definitely more how 'humans' think about the numbers, while little-endian is nice for machines to work with