TheFileTools

How to convert between decimal, hex, binary and octal

Convert a whole number between decimal, hexadecimal, binary and octal, with worked examples and the inputs that cause errors.

Memory addresses and colour codes are written in hexadecimal, bit masks in binary, Unix file permissions in octal, and people think in decimal. Converting between them by hand is slow and error-prone.

Steps

  1. Open Number base converter.
  2. Set Input is to the system your number is written in: Decimal, Hexadecimal, Binary or Octal.
  3. Type the number.
  4. Read all four rows, Decimal, Hexadecimal, Binary and Octal, and press Copy next to the one you need.

Worked examples

  • Decimal 255 is FF in hexadecimal, 11111111 in binary and 377 in octal.
  • Octal 755, the familiar file permission, is 493 in decimal and 111101101 in binary, which is the groups 111, 101 and 101.

Input rules

  • Spaces and underscores are ignored, so digits can be grouped for readability, as in 1111_0000.
  • A leading 0x, 0o or 0b is removed when it matches the chosen base. The prefix does not select the base. Only the Input is setting does, so 0xFF with Decimal selected is an error.
  • Hexadecimal letters may be upper or lower case. The output is in capitals, without a prefix.
  • Negative numbers are written with a minus sign and come out with one: -10 in decimal is -1010 in binary. The tool does not show two's complement.
  • Whole numbers only. A decimal point, or a digit that does not exist in the chosen system such as 8 in octal, gives the message "That is not a number in the chosen system."
  • No size limit. The arithmetic is exact for numbers of any length, including 64-bit values and longer.

A leading zero does no harm: with Hexadecimal selected, 0B5F is read as B5F, because 0b counts as a prefix only when Binary is selected.

Related tools

To convert a whole colour code at once, use Colour converter. For metres, bytes and other units of measurement, use Unit converter. A large decimal number in a log may be a time, which you can check with Unix timestamp converter.