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
- The Number Base Converter
- A whole number to convert (the Try it button loads 255)
Steps
Enter the number
Type
255into Number and leave the base on 10 (decimal).Read every base at once
The results show
1111 1111in binary,377in octal andFFin hexadecimal. Binary is grouped in fours, and each group of four bits matches one hex digit.Check the size
The details show the number needs 8 bits and fits in an unsigned 8-bit integer, which is one byte.
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.
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
00FFandFFgive the same result.
Next steps
Go back to the Number Base Converter, or keep going with one of these: