Binary, hexadecimal, decimal and octal converter
Convert a number between binary, hexadecimal, decimal, octal and any other base from 2 to 36. Compare a hex value from a debugger, inspect individual bits or check a conversion in your code. Large integers keep every digit, and fractions show when a result is approximate.
Loading the tool…
Binary, decimal, hexadecimal and octal: which base do you need?
A number base, also called a radix, determines how much each digit position is worth. Changing the base changes the way a number is written, not its value. Decimal 42, binary 101010, octal 52 and hexadecimal 2A all represent the same quantity.
| Format | Base and digits | Where it helps | Decimal 42 written in this base |
|---|---|---|---|
| Binary | Base 2: 0 and 1 | Inspecting bits, flags, masks and hardware registers | 101010 |
| Decimal | Base 10: 0 to 9 | Reading counts, measurements and values intended for people | 42 |
| Hexadecimal, or hex | Base 16: 0 to 9, then A to F | Reading bytes, memory addresses, packet data and RGB colors | 2A |
| Octal | Base 8: 0 to 7 | Reading Unix file permissions and groups of three bits | 52 |
Binary exposes every bit, while hexadecimal makes long bit patterns easier to read: one hex digit represents four bits, so two hex digits describe one 8-bit byte. Octal groups bits in threes. Decimal is usually easier when the question is “how many?” rather than “which bits are set?”
For example, the color #2A80FF contains three hexadecimal channels: 2A, 80 and FF, or decimal 42, 128 and 255. Convert each channel separately here; use Color Studio to work with the complete color, palettes and contrast. For a permission value such as octal 755, the binary groups are 111 101 101: read/write/execute for the owner, and read/execute for group and others. Its decimal value is 493, not 755.
How to convert between number bases
Binary or hexadecimal to decimal: add the place values
Starting at the right, whole-number positions are worth 1, then the base, then the base squared, and so on. Multiply each digit by its place value and add the results.
- Binary
101010is1 × 32 + 0 × 16 + 1 × 8 + 0 × 4 + 1 × 2 + 0 × 1 = 42. - Hexadecimal
2Ais2 × 16 + 10 × 1 = 42, becauseArepresents ten. - Octal
52is5 × 8 + 2 × 1 = 42.
Decimal to binary or hex: divide and keep the remainders
For a nonnegative integer, repeatedly divide by the destination base. Each remainder supplies a digit; read the remainders from last to first.
To convert decimal 42 to hexadecimal, divide 42 by 16: the quotient is 2 and the remainder is 10 (A). Divide 2 by 16: the quotient is 0 and the remainder is 2. Read upward to get 2A. The same method with division by 2 produces 101010 in binary. For a negative number, convert its magnitude and put the minus sign back; fixed-width signed bytes are a separate question below.
Binary to hex or octal: group the bits
You can skip decimal when converting between these bases. Starting at the right, group binary digits into fours for hex or threes for octal. Add zeros on the left only if the first group is incomplete.
| Binary grouping | Read each group | Result |
|---|---|---|
0010 1010 | 0010 = 2; 1010 = A | Hexadecimal 2A |
101 010 | 101 = 5; 010 = 2 | Octal 52 |
Leading zeros do not change the numeric value: 00101010 and 101010 are both 42. They do communicate a chosen width, which matters when displaying bytes or registers.
Why do programming languages use 0x, 0b and other prefixes?
The digits 10 alone are ambiguous: they mean two in binary, eight in octal, ten in decimal or sixteen in hexadecimal. A prefix tells a language how to interpret the digits. Common forms include 0b101010, 0o52 and 0x2A; the prefix is not part of the value. The JavaScript numeric-literal reference explains these spellings and the n suffix used for BigInt integers.
In this converter, choose the input base explicitly. Matching 0b, 0o and 0x prefixes are accepted, but a leading zero does not automatically select octal. Uppercase and lowercase hex digits mean the same thing. Use Options → Number notation for programming-style results, including prefixes, assembly suffixes, Free Pascal, Visual Basic and JavaScript BigInt. These styles apply to integers in bases 2, 8, 10 and 16; they do not check a target language’s type limits or compiler mode.
Convert numbers in JavaScript, Python, PHP, Java and C#
Most code follows two steps: parse text using its source base, then format the numeric value in the destination base. These examples all start with hexadecimal 2A and print decimal 42, binary 101010, octal 52 and hexadecimal 2a, one per line. They demonstrate positive whole numbers; fraction parsing and signed byte representations need different APIs.
JavaScript: preserve large integers with BigInt
const value = BigInt("0x2A");
console.log(value.toString(10)); // 42
console.log(value.toString(2)); // 101010
console.log(value.toString(8)); // 52
console.log(value.toString(16)); // 2a
Pass the original text to BigInt, rather than first converting it to a Number that may already have lost digits. For example, BigInt("9007199254740993") preserves that integer exactly. BigInt.toString(radix) supports output bases 2–36 and returns digits without a prefix or n suffix. BigInt cannot hold fractions.
Python: parse with int and format the result
value = int("2A", 16)
print(value) # 42
print(format(value, "b")) # 101010
print(format(value, "o")) # 52
print(format(value, "x")) # 2a
Python integers support arbitrary precision, subject to resource and conversion limits. int(text, base) accepts an explicit source base; int("0x2A", 0) instead recognizes the prefix. To keep prefixes in the output, use bin(value), oct(value) or hex(value) rather than the formats shown above.
PHP: convert a small integer string directly
<?php
$hex = "2A";
foreach ([10, 2, 8, 16] as $base) {
echo base_convert($hex, 16, $base), PHP_EOL;
}
base_convert() accepts bases 2–36. Use it carefully: the PHP manual warns that large values can lose precision, and invalid characters may be ignored rather than rejected. This example uses a known-valid, small positive integer; the function is not an input validator or an arbitrary-precision replacement for this converter.
Java: use BigInteger for values beyond long
import java.math.BigInteger;
public class BaseConversion {
public static void main(String[] args) {
BigInteger value = new BigInteger("2A", 16);
for (int base : new int[] {10, 2, 8, 16}) {
System.out.println(value.toString(base));
}
}
}
BigInteger keeps integer precision without the fixed 64-bit range of long. Give its string constructor the digits and an explicit base; do not include 0x in the string passed to this constructor. Formatting a negative BigInteger produces a minus sign, not a fixed-width memory dump.
C#: convert within a signed 64-bit integer range
using System;
long value = Convert.ToInt64("2A", 16);
Console.WriteLine(Convert.ToString(value, 10)); // 42
Console.WriteLine(Convert.ToString(value, 2)); // 101010
Console.WriteLine(Convert.ToString(value, 8)); // 52
Console.WriteLine(Convert.ToString(value, 16)); // 2a
The radix overload of Convert.ToString supports bases 2, 8, 10 and 16. This example uses C# top-level statements and long, so it has a fixed range. Negative values formatted in a non-decimal base use two’s-complement representation; do not assume every language formats negative integers the same way.
Fractions: why 0.1 can become a repeating binary number
Positions after the point use inverse powers of the base. Binary 0.1 means one half; hexadecimal 0.8 means eight sixteenths, also one half. That is why decimal 10.5 converts exactly to binary 1010.1 and hexadecimal A.8.
To convert a fractional part, repeatedly multiply it by the destination base, take the whole-number digit, and continue with the remaining fraction. Decimal 0.5 × 2 = 1 finishes immediately. Decimal 0.1 never finishes in binary: it starts 0.0001100110011…. The Python explanation of floating-point limitations shows why many decimal fractions cannot be stored exactly as binary floats.
Here, ≈ means the displayed fraction was truncated toward zero, not rounded to the nearest value. Increase the fractional-digit limit in Options for more digits; a repeating expansion still will not become finite. Integer digits remain exact, including values such as decimal 9007199254740993, which is hexadecimal 20000000000001.
A number’s base is not its representation in memory
Signed integers and two’s complement
Converting decimal -1 to binary gives the mathematical value -1. Encoding it as an 8-bit signed two’s-complement integer gives 11111111, or hex byte FF. The same eight bits interpreted as unsigned mean 255.
Always identify the width and signedness before interpreting bytes. An 8-bit unsigned integer ranges from 0 to 255; an 8-bit signed integer ranges from -128 to 127. In Machine formats, choose the width and signed setting to inspect this distinction. Out-of-range values are rejected, not wrapped.
IEEE 754 floats and byte order
The number 1 is written 1 in hexadecimal, but its IEEE 754 binary32 encoding is 3F800000. Those bits store a sign, exponent and fraction. Choose binary32 or binary64 in Machine formats when you need the floating-point representation rather than another way of writing the number.
For a multibyte value, endianness determines which byte comes first. The binary32 encoding of 1 is 3F 80 00 00 in big-endian order and 00 00 80 3F in little-endian order. Reordering bytes is not the same as reversing the bits inside each byte. Select the expected byte order before decoding a packet or file field.
Is base conversion the same as Base64 or text encoding?
No. This tool converts the value of a number. The Base16, Base32 and Base64 encodings in RFC 4648 represent sequences of bytes. The numeric base 32 offered here uses digits 0–9 and A–V; it is not RFC 4648 Base32. Likewise, a hexadecimal number alone does not specify a character encoding or a date. Use the URL encoder and decoder for URL text, or the time converter to interpret Unix timestamps.
The browser remembers your input-base and result-list preferences on this device when storage is available; those preferences contain no entered values. The address does contain the current valid input in its The tool accepts up to 2,048 input characters, decimal exponents from -1,024 to 1,024, and 8–128 displayed fractional digits. Calculations run in your browser; all available formats and exports are free, with no account required. This tool processes your data on your device. The text, files, or passwords you enter and the results it creates are not sent to our servers or any other server. Page and asset requests still occur. Production pages also load Google Tag Manager, Cloudflare Web Analytics, and AdSense advertising; tool code does not send inputs or results to analytics or ads. See our privacy policy. To inspect requests while using the tool, open your browser's developer tools and select Network. Try it with sample data. Read How to Check Website Network Requests in Chrome, Firefox, Edge and Safari.How to use this tool
1.5e-3.# fragment. That fragment is not sent in the page request, but people with the link and page scripts can read it, and it may remain in browser history. Empty or invalid input removes the conversion from the address.Your tool data stays in your browser