Hexadecimal shows up everywhere once you start looking: colour codes like #FF6600, memory addresses in error messages, MAC addresses on a router label, file permissions written in octal. Binary sits underneath all of it. Whether you are studying for a computing exam, reading a network packet dump or trying to understand why a value became negative, you will eventually need to move between number bases with confidence.
This guide explains the idea that all number bases share, walks through the manual methods for the most common conversions, and covers two's complement, the scheme computers use for negative integers. You will also see how to check your working instantly in the browser.
One idea behind every base
In a positional number system, each digit is multiplied by a power of the base, depending on its position. Decimal 472 is:
4 × 10² + 7 × 10¹ + 2 × 10⁰ = 400 + 70 + 2
Every other base follows the same rule with a different multiplier:
| Base | Name | Digits used |
|---|---|---|
| 2 | Binary | 0, 1 |
| 8 | Octal | 0-7 |
| 10 | Decimal | 0-9 |
| 16 | Hexadecimal | 0-9, A-F (A = 10 … F = 15) |
Bases above 10 borrow letters for the extra digits. Base 36 uses all ten digits and all 26 letters, which is why it is sometimes used for short IDs and URL shorteners.
In code, prefixes tell you the base: 0b1010 is binary, 0o17 is octal and 0x1F is hex.
Converting to decimal
Multiply each digit by its place value and add. For binary 1101 0110:
1×128 + 1×64 + 0×32 + 1×16 + 0×8 + 1×4 + 1×2 + 0×1 = 214
For hex 2F: 2 × 16 + 15 × 1 = 47.
Converting from decimal
Divide repeatedly by the target base and read the remainders from bottom to top. To turn 214 into hex:
214 ÷ 16 = 13 remainder 6
13 ÷ 16 = 0 remainder 13 (D)
Reading upwards gives D6. The same method works for binary (divide by 2) or any other base.
The shortcut between binary, octal and hex
Because 16 is 2⁴ and 8 is 2³, you never need decimal as a middle step:
- Binary to hex: split the bits into groups of four from the right, and convert each group.
1101 0110becomesD 6. - Binary to octal: split into groups of three.
11 010 110becomes3 2 6, so octal 326. - Hex to binary: replace each hex digit with its four-bit pattern.
A7becomes1010 0111.
This is exactly why hex is popular in computing: one hex digit is always one nibble (four bits), and two hex digits are always one byte.
Check conversions instantly in the browser
The Number Base Converter updates all bases at once as you type, and handles integers far larger than a normal calculator can.
- Open the Number Base Converter. It starts with 255 so you can see FF, 11111111 and 377 side by side.
- Type your number into whichever box matches its base: Decimal, Hexadecimal, Binary or Octal. The other boxes update immediately.
- You can paste values with prefixes such as
0x,0band0o, and with spaces or underscores between digits. A leading minus sign is accepted. - For any other base, pick it under Custom base (base 2 to base 36) and type into that field.
- Switch on Group digits for readability to show binary in groups of four, hex in pairs and decimal with thousands separators. The copy buttons always copy the plain, ungrouped value.
- Check the Summary panel for the sign, the number of bits needed and the number of decimal digits.
- Look at Two's complement (signed integers) to see how the value is stored in 8, 16, 32 and 64 bits, including the hex pattern and the unsigned reading of the same bits.
If you type a digit that is not valid for the base, for example a 2 in the binary box, the tool tells you which character is the problem.
Negative numbers and two's complement
Computers store signed integers in a fixed number of bits using two's complement. To find the pattern for a negative number:
- Write the positive value in binary, padded to the width, e.g. 5 in 8 bits is
0000 0101. - Invert every bit:
1111 1010. - Add one:
1111 1011.
So -5 in 8 bits is 1111 1011, or 0xFB. Read as an unsigned number, the same bits mean 251. That dual reading explains many real bugs: a value of 251 read from a device suddenly appearing as -5, or a counter wrapping from 127 to -128 in a signed byte.
The range of an n-bit signed integer is -2ⁿ⁻¹ to 2ⁿ⁻¹ − 1. An 8-bit signed integer holds -128 to 127; a 32-bit one holds about ±2.1 billion.
Other ways to convert
Operating system calculators
Windows Calculator has a Programmer mode with HEX, DEC, OCT and BIN side by side and a choice of word size. macOS Calculator has a Programmer view as well. These are excellent for everyday work, and they also show bit toggles. Their limit is the word size, usually 64 bits.
Spreadsheets
Excel and Google Sheets have DEC2BIN, DEC2HEX, HEX2DEC, BIN2DEC and related functions, plus BASE(number, base) for arbitrary bases. The binary functions accept only small values, so they are best for quick lookups in a table.
Programming languages
Python makes conversions short and has unlimited integer size:
int("ff", 16) # 255
hex(255) # '0xff'
bin(214) # '0b11010110'
format(-5 & 0xFF, "08b") # '11111011'
JavaScript's parseInt(str, base) and n.toString(base) do the same, with BigInt for large values.
Tips and common mistakes
Leading zeros matter for width, not value
0101 and 101 are the same number, but when you are working with bytes, padding to eight bits makes grouping and two's complement readable.
Hex letters are case-insensitive
0xff, 0xFF and 0xFf are identical. Pick one style for consistency in documents.
Don't confuse text with numbers
Converting the number 65 to binary gives 1000001. Converting the character "A" gives the same bits only because A's code happens to be 65. To turn words into binary or hex byte by byte, use a text to binary converter, and see the ASCII table for character codes.
Colours and permissions
A hex colour is three bytes: #1E90FF is red 30, green 144, blue 255. A colour converter does this translation for you. Unix permissions like 755 are octal, one digit each for owner, group and others; the chmod calculator explains each bit.
Frequently asked questions
Why do programmers use hexadecimal instead of binary?
Hex is far shorter and maps cleanly onto binary, with one digit per four bits. A 32-bit value is 8 hex digits instead of 32 binary digits.
What is the largest number this converter can handle?
It uses arbitrary-precision integers, so very long numbers convert exactly. Fractions and decimals are not supported; it works with whole numbers only.
How do I know how many bits a number needs?
Convert it to binary and count the digits, or check the "Bits needed" figure in the tool's summary. Add one more bit if you need to store it as a signed value.
Is octal still used?
Mostly for Unix file permissions and in some older systems and file formats. Hex has replaced it in most other places.
Why does my negative number show as a large positive one?
The bits are being read as unsigned. In two's complement, a pattern starting with 1 is negative when read as signed but a large positive number when read as unsigned.