Working With Binary Data

Convert decimal to hexadecimal

Steps:
  1. Divide the decimal number by 16. Treat the division as an integer division.
  2. Write down the remainder (in hexadecimal).
  3. Divide the result again by 16. Treat the division as an integer division.
  4. Repeat step 2 and 3 until result is 0.
  5. The hex value is the digit sequence of the remainders from the last to first.
Video: How To Convert Decimal to Hexadecimal


Convert hexadecimal to decimal

Video: How to convert hexadecimal to decimal


Convert hexadecimal to binary

Convert each nibble (4 bits) to binary


Convert binary to hexadecimal

Write each set of 4 bits as a hexadecimal digit


Extract a nibble

Use a mask of 11112 or 0xf or 1610 and & it with the nibble that you wish to extract


What is BCD (binary coded decimal)

It is a byte expressed as a 2 digit hexadecimal number that is interpreted as a decimal value.
For example:

Consider the hexadecimal number 0x25.  As a decimal value, it would be equal to 37.  But as a BCD value, it is 25.