PRACTICAL GUIDE

Convert Binary and Hexadecimal Values Safely

The digits 10 mean ten in decimal but two in binary.

Identify the source base

The digits 10 mean ten in decimal but two in binary. Always select the base before interpreting a value. Hexadecimal adds A through F for values ten through fifteen; a digit must be smaller than its base.

Check place values

Hexadecimal 2A is 2 × 16 + 10, which is 42 in decimal. Binary 101010 represents 32 + 8 + 2, giving the same value. These small examples are useful checks of the chosen conversion direction.

Leave prefixes out of the value field

Enter FF with source base 16, rather than 0xFF. Leading zeros do not change a whole number’s value, and the output is not padded to a fixed width. Add display padding separately if a file format requires it.

State the negative-number convention

A signed mathematical value and a fixed-width bit pattern are different descriptions. The converter uses a leading minus sign. It does not infer a word size, signed machine type, overflow wraparound or a two’s-complement interpretation.

Put it into practice