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.

FormatBase and digitsWhere it helpsDecimal 42 written in this base
BinaryBase 2: 0 and 1Inspecting bits, flags, masks and hardware registers101010
DecimalBase 10: 0 to 9Reading counts, measurements and values intended for people42
Hexadecimal, or hexBase 16: 0 to 9, then A to FReading bytes, memory addresses, packet data and RGB colors2A
OctalBase 8: 0 to 7Reading Unix file permissions and groups of three bits52

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 101010 is 1 × 32 + 0 × 16 + 1 × 8 + 0 × 4 + 1 × 2 + 0 × 1 = 42.
  • Hexadecimal 2A is 2 × 16 + 10 × 1 = 42, because A represents ten.
  • Octal 52 is 5 × 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 groupingRead each groupResult
0010 10100010 = 2; 1010 = AHexadecimal 2A
101 010101 = 5; 010 = 2Octal 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.

How to use this tool

  1. Choose the base beside Value, then enter your number. Use a dot for fractions and a minus sign for negatives. Single spaces or underscores may separate digits; decimal accepts scientific notation such as 1.5e-3.
  2. Read or copy the equivalents. A result’s arrow converts it into the input and moves the old input base into that row. Changing the input-base selector instead keeps the digits and reinterprets them. Truncated or overlong results cannot be swapped into the input.
  3. Use More bases to search missing bases and see their values. Click a row to add it and close, or + to keep adding. Drag a row’s grip to reorder it; click the grip to move or remove it with the menu. Escape closes dialogs or cancels a drag.
  4. Use Options for fractional precision, digit case, grouping and programming notation. Prefix/suffix styles apply to integers, omit grouping spaces and leave fractions and other bases plain. They change output, not accepted input syntax; the arrow uses plain digits. Reset defaults restores decimal 255, the binary/octal/hex result list and default display/machine settings.
  5. The copy button beside Equivalent values includes the input and selected results only. Toolbar copy/download includes all 35 bases. Copy conversion link preserves the input, selected bases, order and display options for sharing or bookmarking.
  6. Machine formats inspects signed/unsigned 8-, 16-, 32-, 64- and 128-bit integers or IEEE 754 binary32/binary64. Paste the required number of hex bytes to decode them. Finite results can become the input; infinity and NaN cannot.

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 # 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.

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.

Your tool data stays in your browser

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.

Premium is coming soon

An optional premium subscription to remove ads is planned. Subscriptions are not available yet.

You can keep using our free tools without an account.