Number Base Converter · Tutorial

How to convert decimal numbers to binary and hex

4 min readbeginnerUpdated

You need the binary and hex forms of a decimal value, for a bitmask, a colour, a permission or a homework answer. This tutorial converts 255 to every common base, explains why the results look the way they do, and shows what changes for negative numbers.

What you need

Steps

  1. Enter the number

    Type 255 into Number and leave the base on 10 (decimal).

  2. Read every base at once

    The results show 1111 1111 in binary, 377 in octal and FF in hexadecimal. Binary is grouped in fours, and each group of four bits matches one hex digit.

  3. Check the size

    The details show the number needs 8 bits and fits in an unsigned 8-bit integer, which is one byte.

  4. Try a negative number

    Change the number to -42. The details now show its two's complement form in a signed 8-bit integer, 1101 0110, which is how a computer stores it.

Try it yourself

Opens the Number Base Converter with this tutorial's sample loaded.

Try it now

Common mistakes

Picking the wrong source base
"10" means ten in decimal but two in binary. Make sure the base matches how the number is written.
Expecting fractions
Only whole numbers are converted. Use the IEEE 754 Converter for decimals like 0.1.
Leading zeros
Leading zeros don't change the value, so 00FF and FF give the same result.

Next steps

Go back to the Number Base Converter, or keep going with one of these: