If you are not familiar with binary numbers and bits please remember, that they always start with the most significant bit first. This is not special to the RFzero or Arduino but a general principle. This is in fact similar to the decimal system, where we also start with the most significant digit first, e.g. 7042 is seven thousands, zero hundreds, four tens and two ones which is equal to 7 • 1000 + 0 • 100 + 4 • 10 + 2 • 1 = 7 • 10^{3} + 0 • 10^{2} + 4 • 10^{1} + 2 • 10^{0}.

Please remember that x^{y} is the same as x-value multiplied by itself y-number of times, e.g. 10^{3} = 10 • 10 • 10 = 1000.

If we have the binary number 1000101 we can do the same principle break down as we did with the 7042 decimal number above. But instead of the base being ten (10) in the decimal world, it is two (2) in the binary world, i.e. 1000101 can be expressed as 1 • 2^{6} + 0 • 2^{5} + 0 • 2^{4} + 0 • 2^{3} + 1 • 2^{2} + 0 • 2^{1} + 1 • 1^{0} = one sixty-fours, zero thirty-twos, zero sixteens, zero eights, one fourths, zero twos and one ones, which is equal to 69 in decimal notation. For hexadecimal numbers the base is 16 instead, e.g. 1A2B can be expressed as 1 • 16^{3} + 10 • 16^{2} + 2 • 16^{1} + 11 • 16^{0} = 6699 in decimal notation, because A = 10, B = 11, C = 12, D = 13, E = 14 and F = 15.

Oh, please remember always to multiply/divide before adding/subtracting! Otherwise your old math teacher will be after you.

*Binary, decimal and hexadecimal conversion table.*

Bin | Dec | Hex | Bin | Dec | Hex | Bin | Dec | Hex | Bin | Dec | Hex | |||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|

0000 | 0 | 0 | 0100 | 4 | 4 | 1000 | 8 | 8 | 1100 | 12 | C | |||

0001 | 1 | 1 | 0101 | 5 | 5 | 1001 | 9 | 9 | 1101 | 13 | D | |||

0010 | 2 | 2 | 0110 | 6 | 6 | 1010 | 10 | A | 1110 | 14 | E | |||

0011 | 3 | 3 | 0111 | 7 | 7 | 1011 | 11 | B | 1111 | 15 | F |

Converting binary bits to hex is easier than you may think. Simply take four bits starting from the right, and convert them to hex, then take the next group of four bits moving left and so on, until there are no more bits left, see the table below.

*Examples of converting binary numbers to hexadecimal.*

Decimal | Binary | Groups of four | Hex | Hex notation |
---|---|---|---|---|

0 | 00000000 | 0000 0000 | 0 0 | 0x00 |

22 | 00010110 | 0001 0110 | 1 6 | 0x16 |

69 | 01000101 | 0100 0101 | 4 5 | 0x45 |

255 | 11111111 | 1111 1111 | F F | 0xFF |

If there is less than four bits just imagine that the missing bits to the left are zeros, e.g. 110100 => 00110100.

You may also use a program to do the conversion for you. In Windows and Mac OS there are programs called Calculator, that can be changed to Programmer mode. In Linux there is to many to mention.

*Example of the Windows Calculator in Programmer mode (Menu | View | Programmer).*

Generally when programming in C and variants

- Binary numbers must be prefixed 0b, e.g. 0b10101111
- Decimal numbers are often not prefixed but can be 0d, e.g. 0d7042
- Hexadecimal numbers must be prefixed 0x, e.g. 0x1F
- If a number begins with zero (0) it is an octal number, which is not used very often. But take care not to write e.g. 01011111, and think it is a binary number because it isn’t