Skip to main content
Best Answer Hub logo Best Answer Hub.
Back to Playbooks
Best Answer Hub Playbooks · Developer Tools
Same number, many faces

Binary, Hex, and Octal: How Base Conversion Works

The number 37 can be written as 100101, 45, 37, or 25 depending on the base. Converting between them is simple arithmetic until negative numbers show up, where the answer depends on how many bits you are using. Here is how base conversion works, why one hex digit is exactly four bits, and the two's-complement trap that catches people out.

Convertany base, 2 to 36
Understandhex, binary, octal
Signedtwo's complement
4
bits in one hexadecimal digit
Princeton COS 217
2 to 36
bases this converter handles
Best Answer Hub
8 vs 16
bit widths that change a negative number
Univ. of Oregon
755
the octal chmod for rwxr-xr-x
Linux man page

Number base conversion is positional arithmetic: each digit is worth the base raised to the power of its position, so the same value can be written in binary, octal, decimal, or hexadecimal without changing what it is. The one place it gets subtle is negative numbers, where the binary form depends on the bit width you choose. The Best Answer Hub Number Base Converter converts across bases 2 to 36 at once, handles two's complement with an explicit bit width, and runs in your browser.

This guide covers how base conversion actually works, why hexadecimal is the compact shorthand for binary, the two's-complement bit-width trap, and where each base turns up in real work. The tool sits in the Best Answer Hub Developer Toolbox and its STEM calculator suite, is built and maintained by Shahbaz Ali Malik, and stays free because Best Answer Hub is funded by optional paid assessments rather than advertising.

Start here

What is the Best Answer Hub Number Base Converter?

The Best Answer Hub Number Base Converter is a free, browser-based tool that converts a number between any bases from 2 to 36, using arbitrary-precision arithmetic so large values stay exact. It shows all the common bases at once, auto-detects the 0x, 0b, and 0o prefixes, and includes a two's-complement mode with a selectable bit width for signed numbers. Everything runs in your browser with no signup and nothing uploaded.

  • 1
    Any base, all at once. Convert across bases 2 to 36 and see binary, octal, decimal, and hex together, not one at a time.
  • 2
    Signed numbers done right. A two's-complement mode with an explicit bit width, so a negative value is never ambiguous.
  • 3
    Exact at any size. Arbitrary-precision arithmetic means very large numbers convert without rounding.
The mechanics

How does base conversion work?

Every number is a sum of its digits, each multiplied by the base raised to the power of its position. In base 2, the number 100101 is 1 times 32, plus 1 times 4, plus 1 times 1, which is 37 (Princeton COS 217). To go the other way, from decimal to another base, you divide repeatedly by the target base and read the remainders from bottom to top. The four common bases just use different digit sets.

BaseNameDigits37 looks like
2Binary0-1100101
8Octal0-745
10Decimal0-937
16Hexadecimal0-9, A-F25
Positional notation, worked out
100101 (base 2) = 1x32 + 0x16 + 0x8 + 1x4 + 0x2 + 1x1 = 32 + 4 + 1 = 37 (base 10)

The same method works for any base: multiply each digit by the base to the power of its position, then add. Source: Princeton COS 217.

The compact one

Why does hexadecimal exist?

Because one hex digit maps exactly to four binary digits, making hex a tidy shorthand for binary. Since 16 is 2 to the fourth power, every hex digit from 0 to F stands for a group of four bits, so a byte (8 bits) is just two hex digits (Princeton COS 217). That is why hex shows up wherever raw bytes do, including CSS colors, where each of the red, green, and blue channels is a two-digit hex value from 00 to ff (MDN).

One hex digit equals four bits
C6 hexadecimal 1100 C = 12 0110 6 = 6 198 decimal

Each hex digit expands to exactly four bits (C = 1100, 6 = 0110), so C6 is 11000110, which is 198. Source: Princeton COS 217; MDN.

The gotcha

The two's complement trap: why bit width matters

A negative number has no single binary form: it depends on how many bits you are using. Computers store signed integers in two's complement, where the top bit carries a negative place value, so the same value fills a different pattern at 8, 16, or 32 bits. As one university course puts it, "when we describe the representation of a negative binary number, we need to say how many bits are in the representation," noting that minus one is 11111111 in 8 bits but 1111111111111111 in 16 bits (University of Oregon, CIS 211).

The same negative, at different widths
-1 as 8-bit twos complement = 11111111 -1 as 16-bit twos complement = 11111111 11111111 -8 as 4-bit twos complement = 1000 (the lowest 4-bit value) +7 as 4-bit twos complement = 0111 (the highest 4-bit value)

A converter that ignores bit width cannot answer "what is -1 in binary" correctly. The Best Answer Hub Number Base Converter asks for the width. Source: University of Oregon, CIS 211.

This is the single most common base-conversion mistake, and it is why the Best Answer Hub Number Base Converter makes you pick a bit width for signed values instead of guessing. It also flags digits that are invalid for a base, so a stray 2 in a binary number does not silently produce a wrong answer.

In the wild

Where do you actually use each base?

Each base earns its keep in a different corner of computing. Hexadecimal writes colors and bytes, octal sets file permissions, and binary underlies logic and networking. If you have ever run chmod 755, you have used octal: each digit is read (4) plus write (2) plus execute (1) for owner, group, and others, so 755 means rwxr-xr-x (Linux man page).

BaseWhere it shows up
BinaryDigital logic, bitmasks, IP subnetting
OctalUnix file permissions (chmod 755)
HexadecimalCSS colors, memory addresses, byte dumps

Because these come up constantly and are easy to get slightly wrong, a converter that shows every base at once and is strict about bit width and valid digits saves real debugging time.

Why this one

How is Best Answer Hub different from other converters?

The difference is range and rigor. Many free converters only do binary, octal, decimal, and hex; the Best Answer Hub Number Base Converter handles any base from 2 to 36, shows them together, and treats signed numbers properly with an explicit bit width. It uses arbitrary-precision arithmetic so large values do not lose accuracy, and it runs entirely in your browser.

What you getBest Answer HubTypical converter
Bases supported2 to 36Often just 2, 8, 10, 16
Two's complement with bit widthYes, explicitOften missing
Large-number precisionArbitrary precisionCan overflow
Signup or adsNone, in browserVaries
Convert across every base

Try the free Number Base Converter

Binary, octal, decimal, hex, and any base to 36, with two's complement and arbitrary precision. No signup, in your browser.

Open the Number Base Converter
Good questions

Frequently asked questions about number bases

What is the Best Answer Hub Number Base Converter?
The Best Answer Hub Number Base Converter is a free, browser-based tool that converts a number between any bases from 2 to 36 with arbitrary-precision arithmetic. It shows the common bases at once, detects 0x, 0b, and 0o prefixes, and includes a twos-complement mode with a selectable bit width. Nothing is uploaded.
How do you convert binary to decimal?
Multiply each binary digit by 2 raised to the power of its position, then add. So 100101 is 32 plus 4 plus 1, which is 37. The Best Answer Hub Number Base Converter does this instantly and shows the result in decimal, hex, and octal at the same time, so you do not have to work it out by hand.
Why is one hex digit four bits?
Because 16 is 2 to the fourth power, so each hexadecimal digit from 0 to F stands for exactly four binary digits. That makes hex a compact way to write bytes: 8 bits is two hex digits. The Best Answer Hub Number Base Converter shows the binary and hex forms side by side so the mapping is clear.
Why does a color code use hexadecimal?
Because each color channel is one byte, from 0 to 255, which is exactly two hex digits. A code like #C60018 sets red, green, and blue as three two-digit hex values. The Best Answer Hub Number Base Converter converts each channel between hex and decimal so you can read or build a color code.
What is twos complement?
It is how computers store signed integers in binary. The most significant bit carries a negative place value, so the pattern encodes negative numbers. Because of this, a negative value needs a fixed bit width. The Best Answer Hub Number Base Converter includes a twos-complement mode where you set that width.
Why does my negative number look different at 8 and 16 bits?
Because twos complement depends on the bit width. Minus one is 11111111 in 8 bits but 1111111111111111 in 16 bits. There is no single binary form for a negative number without a width. The Best Answer Hub Number Base Converter asks for the width so the answer is always correct.
How do I read a chmod number like 755?
It is octal, base 8. Each digit adds read (4), write (2), and execute (1) for the owner, group, and others. So 755 means rwxr-xr-x. The Best Answer Hub Number Base Converter converts between octal and binary, which is how permission bits are actually stored, so 755 becomes 111101101.
What bases does the converter support?
Any base from 2 to 36, using the digits 0 to 9 and then A to Z. That covers binary, octal, decimal, and hexadecimal, plus less common bases like base 32. Most free converters stop at hex, but the Best Answer Hub Number Base Converter handles the full range and shows the common ones together.
Can it handle very large numbers?
Yes. The Best Answer Hub Number Base Converter uses arbitrary-precision arithmetic, so numbers far beyond the usual 64-bit limit convert exactly with no rounding or overflow. This matters for cryptographic values, large hex dumps, and any case where a standard calculator would silently lose digits.
What is the difference between signed and unsigned?
An unsigned number is always zero or positive and uses every bit for magnitude. A signed number uses twos complement, so the top bit marks it negative, which halves the positive range. The Best Answer Hub Number Base Converter lets you switch between the two, so the same bits can be read either way.
Why is my binary number rejected?
Usually because it contains a digit that is not valid for base 2, which only allows 0 and 1. A stray 2 or 9 is not binary. The Best Answer Hub Number Base Converter flags digits that are invalid for the chosen base rather than producing a wrong answer, so you catch the typo immediately.
Do I need to add a 0x or 0b prefix?
You can, and the Best Answer Hub Number Base Converter auto-detects 0x for hex, 0b for binary, and 0o for octal. You can also just pick the base from the menu and type the digits. Either way, the converter shows the value across the other bases at the same time.
Is my data uploaded to a server?
No. The Best Answer Hub Number Base Converter runs entirely in your browser, so the numbers you convert never leave your device. There is no signup and no server-side processing, which is consistent with how every Best Answer Hub tool is built. The conversion is exact arithmetic done locally.
Does it work offline?
Yes. Once the Best Answer Hub Number Base Converter page has loaded, it works with no internet connection, because base conversion is deterministic arithmetic that needs no external data. That makes it reliable on a locked-down machine or anywhere a connection is not available.
Is the Number Base Converter free?
Yes. The Best Answer Hub Number Base Converter is completely free with no usage limits, no watermarks, and no signup. It stays free because Best Answer Hub is funded by optional paid assessments rather than advertising, so it carries no ads and never gates a conversion behind an upgrade.
People also read

Keep going

Sources

More free developer tools: Developer Toolbox, Hash Generator, Color Palette Generator, and all free tools.

Built & maintained by Shahbaz Ali Malik Last updated: