Skip to content
Conversion

Binary Converter - Decimal, Hex, Octal

Enter a number in any base and instantly see its equivalent in all four numeral systems: binary (base 2), decimal (base 10), hexadecimal (base 16), and octal (base 8). Choose your input base, pick signed or unsigned mode and a bit width, and the step-by-step panel shows exactly how each conversion is done.

Your details

The base of the number you are entering.
Type the number to convert. Binary accepts 0 and 1 only, hex accepts 0-9 and A-F.
Unsigned numbers are always non-negative. Signed uses two's complement to represent negatives.
Determines the range of representable values and how many binary digits are shown.
Decimal
42

Base 10 representation

Binary0010 1010
Hexadecimal2A
Octal52
Set bits (ones)3 of 8
Bytes1 byte

42 decimal = 0x2A hex = 0o52 octal

  • In hexadecimal: 0x2A - used in HTML color codes, memory addresses, and low-level programming.
  • This number has 3 set bits out of 8, a 38% bit density (called the Hamming weight or popcount).

Next stepUse the hex output to look up color values (#RRGGBB), memory offsets, or CPU registers. Octal is common in Unix file permissions (chmod 755 means 111 101 101 in binary).

How number bases work

Every number base represents quantity using a fixed set of digits and a positional weighting system. Decimal (base 10) uses digits 0-9, and each position is worth ten times the one to its right. Binary (base 2) uses only 0 and 1, and each position is worth twice the one to its right. That is why 1011 in binary equals 1x8 + 0x4 + 1x2 + 1x1 = 11 in decimal. Hexadecimal (base 16) extends the digit set to 0-9 and A-F, where A=10 and F=15, making it a compact shorthand for binary: one hex digit represents exactly four binary digits (a nibble). Octal (base 8) uses digits 0-7, and one octal digit represents exactly three binary digits, which is why it appears in Unix file permissions like chmod 755.

How to convert between bases

To convert decimal to binary, divide the number by 2 repeatedly and collect the remainders from bottom to top. For example, 42 divided by 2 gives 21 remainder 0, then 10 remainder 1, then 5 remainder 0, then 2 remainder 1, then 1 remainder 0, then 0 remainder 1 - reading the remainders upward gives 101010. To convert binary to hexadecimal, split the binary string into 4-bit groups from the right and replace each group with its hex digit: 1010 becomes A and 0010 becomes 2, so 00101010 becomes 0x2A. For octal, split into 3-bit groups instead: 101 010 becomes 5 2, so octal 52. These rules work in both directions, and the step-by-step panel in this calculator shows every stage.

Signed vs unsigned integers and two's complement

An unsigned 8-bit integer stores values from 0 to 255 using all 8 bits for magnitude. A signed 8-bit integer can represent -128 to +127 by reserving the most significant bit (bit 7) as a sign indicator, but most computers use two's complement rather than a simple sign bit. In two's complement, a negative number is formed by inverting all bits of the positive version and adding 1. So -1 in 8-bit two's complement is 11111111 (0xFF), and -128 is 10000000 (0x80). Two's complement has the elegant property that ordinary binary addition works correctly for both positive and negative numbers without special hardware. This calculator shows the two's complement bit pattern when you select signed mode.

Where you use these bases in practice

Binary is the native language of digital logic: every bit in memory, every CPU register, and every network packet is ultimately a string of 0s and 1s. Hexadecimal is used everywhere binary needs to be shown concisely: RGB web colors (#FF5733), memory addresses (0x7fff5fbff8c0), and machine code listings. Octal survives mainly in Unix/Linux file permissions, where each of the three permission groups (owner, group, others) maps to a 3-bit pattern: rwx = 111 = 7, rw- = 110 = 6, r-- = 100 = 4. Knowing how to read and convert between these bases is a core skill for programmers, network engineers, and electronics engineers.

Common number conversions - binary, decimal, hex, octal

DecimalBinaryHexOctalNotes
0000000Zero
1000111Least significant bit
20010222^1
40100442^2
810008102^3
100000 1010A12Decimal 10
150000 1111F17Max nibble
160001 000010202^4
320010 000020402^5
640100 0000401002^6
1270111 11117F177Max signed 8-bit
1281000 0000802002^7
2551111 1111FF377Max unsigned 8-bit, 0xFF
2560001 0000 00001004002^8
10240000 0100 0000 000040020002^10, one kibibit

Quick reference for frequently used values in programming and electronics.

Frequently asked questions

How do I convert binary to decimal?

Multiply each binary digit by its positional power of 2, then add the results. Starting from the rightmost digit (position 0): 1x2^0 = 1, 1x2^1 = 2, 0x2^2 = 0, 1x2^3 = 8. So binary 1011 = 8 + 0 + 2 + 1 = 11 in decimal. This calculator shows the full breakdown in the step-by-step panel.

How do I convert decimal to binary?

Divide the decimal number by 2 repeatedly, recording the remainder each time. When the quotient reaches 0, read the remainders from bottom to top. For example, 13: 13/2=6 r1, 6/2=3 r0, 3/2=1 r1, 1/2=0 r1 - reading up gives 1101. Enter 13 in this converter and select "Show steps" to see this worked out.

What is the difference between signed and unsigned binary?

Unsigned binary treats all bits as magnitude, so an 8-bit unsigned integer holds 0 to 255. Signed binary (using two's complement) reserves the most significant bit as a sign indicator, giving a range of -128 to +127 for 8 bits. The bit pattern for -1 in 8-bit two's complement is 11111111, the same as 255 unsigned, which is why the sign mode matters when interpreting binary.

Why is hexadecimal used in computing?

Each hex digit represents exactly 4 binary digits (a nibble), so a 32-bit value that would take 32 binary characters to write needs only 8 hex digits. This makes hex a compact, human-readable shorthand for binary. It appears in HTML/CSS color codes, memory addresses, error codes, and IP/MAC addresses for this reason.

What does 0xFF mean?

0x is the conventional prefix for hexadecimal numbers. FF in hex is 15x16 + 15 = 255 in decimal, or 11111111 in binary. It is the maximum value of an unsigned 8-bit byte and appears frequently in color codes (full red = 0xFF0000), bit masks, and initialization patterns.

What is the Hamming weight or popcount?

The Hamming weight (also called popcount or population count) is the number of 1-bits in a binary representation. For 42 (binary 00101010), the Hamming weight is 3 because there are three 1s. It is used in error detection, cryptography, and as a fast CPU instruction (POPCNT) in modern processors.

Sources

Written by Dr. Nadia Petrov, PhD Physicist & Metrologist · Geneva, Switzerland

Bridging fundamental metrology and everyday measurement so every conversion carries the precision its context demands.

Search 3,500+ calculators

Loading search…