Tag Archives: register

How to easy convert binary number to hexadecimal

This type of conversion from binary to hexadecimal often needed during microprocessors registers configuration. By reading microprocessors datasheet you can found what specified registers bit must be set, but how to convert it to hexadecimal number and use it in program code? Below example with Atmega8 TCCR2 register.

Lets convert 01101001 to 0x69.

  1. Split byte by half
  2. Above both parts each bite write these numbers 8 4 2 1 (2^n)
  3. In both parts separately sum up numbers if bite below is 1
  4. Remember it’s hexadecimal number system, 10 – A, 11 -B, 12 -C, 13 -D, 14 -E, 15 – F.
  5. Congratulation, you now have two hexadecimal number digits.