Bit Order vs. Byte Order

Big Endian vs. Little Endian

Let's take the string 'CTF{0123456789}' . We split the string into characters and convert each character to its hexadecimal representation. Then we concatenate the hex values into a hex-string. To do so we could for example use an ascii table (see below). 

We end up with following hex-string.

'CTF{0123456789}' -> 0x4354467b303132333435363738397d

| Hex  |  Binary  | Dec | Char |

+------+----------+-----+------+

| 0x43 | 01000011 |  67 | 'C'  |

| 0x54 | 01010100 |  84 | 'T'  |

| 0x46 | 01000110 |  70 | 'F'  |

| 0x7b | 01111011 | 123 | '{'  |

| 0x30 | 00110000 |  48 | '0'  |

| 0x31 | 00110001 |  49 | '1'  |

| 0x32 | 00110010 |  50 | '2'  |

| 0x33 | 00110011 |  51 | '3'  |

| 0x34 | 00110100 |  52 | '4'  |

| 0x35 | 00110101 |  53 | '5'  |

| 0x36 | 00110110 |  54 | '6'  |

| 0x37 | 00110111 |  55 | '7'  |

| 0x38 | 00111000 |  56 | '8'  |

| 0x39 | 00111001 |  57 | '9'  |

| 0x7d | 01111101 | 125 | '}'  |

+------+----------+-----+------+

| 0x00 | 00000000 |   0 | '\0' | 

In memory the character string 'CTF{0123456789}'  actually gets stored as a bit-sequence. We can create that by converting the 2-digit hex values which represents 1 Byte to the corresponding bit sequence. We would get following bit sequence( 15 * 8 bits = 120 bits ):

0x4354467b303132333435363738397d -> 

010000110101010001000110011110110011000000110001001100100011001100110100001101010011011000110111001110000011100101111101

Unfortunately depending on the architecture and/or if we transmit strings over a network connection it is not as straight forward to determine the bit sequence as we just did. We have to consider the Byte order for the given type we are dealing with. 

Intel for example is storing Byte sequences in Little Endian order. If we transmit strings over a network connection it is usually done in Big Endian Byte order. 

Our string in Big Endian Order would look like this

0x4354467b303132333435363738397d

and in Little Endian Byte Order it would be

0x7d393837363534333231307b465443

011111010011100100111000001101110011011000110101001101000011001100110010001100010011000001111011010001100101010001010100