It wasn't me. You can't prove anything.


2007-06-05

More Big Endian vs Little Endian

Remember, 16 bit hex is two digits at a time. so 01 = 1 and ff = 255 regardless of which endian you are using. It matters what order all your sets of two hex digits are set in that makes the difference in endian.

Decimal
Big Endian Hex
Little Endian Hex
1 0001
0100
2
0002
0200
...


14
000e
0e00
15
000f
0f00
16
0010
1000
17
0011
1100
..


31
001f
1f00
32
0020
2000
33
0021
2100
...


254
00fe
fe00
255
00ff
ff00
256
0100
0001
257
0101
0101
258
0102
0201

Big endian puts the most significant byte first (two places in hex) This is how western culture is used to seeing numbers represented.
01 = 0001 = 000001 = 00000001 = 1

Little endian puts the least significant byte first. Back-assword from normal.
01 = 0100 = 010000 = 01000000 = 1

Understanding the concept is nothing. The trouble is knowing when to switch between them. PPC chips are big endian if I remember right. X86 (the standard Intel/AMD) chips are little endian. Every frigging chip and board has a potential of switching for no good reason. You just have to know which you are dealing with. Some say little endian has an advantage because you can just keep tacking bytes on and getting bigger numbers. I've never heard of a useful program that used that. It seems they all define a byte count before doing anything. I don't know. I can't imagine a real advantage of one over the other.

For the first time in my life today, I had to write code that deals directly with this issue. Normally, I skirted the issue closely, but never had to dive in. I never had to count bits and bytes until this project. I feel all grown up. =]

No comments: