Skip to main content

Number base converter: binary, octal, decimal, hex

Number base converter from 2 to 36: 255 = FF in hexadecimal = 11111111 in binary = 377 in octal. Positional notation, division method, #RRGGBB colours, chmod 755 permissions and bit masks.

  • Clipboard

Embed this widget

Customize the result, check the live preview, then copy the code.

Preview

Embed code type

Code to copy

Responsive and automatically resized by Bethemesh.

Number to convert

Was this tool useful?

How does this tool work?

Enter an integer in any base from 2 to 36 and read it at once in binary, octal, decimal and hexadecimal, plus the target base of your choice. Use it to decode a #RRGGBB colour, read Unix permissions like chmod 755, write a bit mask, check a number-systems exercise or handle base-36 identifiers.

In a positional system of base b, each digit is worth its place value, a power of b: 1F4 in base 16 equals 1 × 256 + 15 × 16 + 4 = 500. Bases above 10 use letters: A = 10, B = 11, up to F = 15 in hexadecimal and Z = 35 in base 36. Case is ignored when you type.

To go from decimal to base b, divide repeatedly by b and read the remainders from bottom to top: 500 = 31 × 16 + 4, then 31 = 1 × 16 + 15, so 1F4. Binary, octal and hexadecimal are linked because 8 = 2^3 and 16 = 2^4: one octal digit is 3 bits and one hex digit is 4 bits. So binary 1010 1010 groups into A and A, giving AA, or 170 in decimal.

Calculations use arbitrary-size integers: 18446744073709551615 (2^64 − 1) converts exactly to FFFFFFFFFFFFFFFF, which an ordinary JavaScript number cannot represent. The prefixes 0b, 0o and 0x are accepted for bases 2, 8 and 16, and spaces or underscores are ignored. A leading minus or plus sign is accepted.

Limits: only integers are handled, so fractional values such as 3.5 are rejected. A negative number is displayed with its sign (−42 gives −101010), not in two's complement, which depends on a chosen bit width. A digit that does not exist in the source base, such as 2 in binary, is reported.

How to use this tool

  1. Enter the number and its base

    Type the integer (with or without a 0x, 0b or 0o prefix) and pick the source base: 2, 8, 10, 16, 36 or a custom value from 2 to 36.

  2. Pick the target base

    Binary, octal, decimal and hexadecimal results are always shown, and the target base appears in its own field.

  3. Adjust the display

    Choose upper or lower case, and group digits by 4 (binary, hex) or 3 to make long values easier to read.

Positional notation and changing base

An integer N is written in base b with digits d_i between 0 and b − 1.

Value of a number written in base b

N = Σ d_i × b^i (i from 0 to n − 1)

Each digit is multiplied by the power of b of its place, the rightmost digit having place 0.

Euclidean division

N = q × b + r

The remainder r is the lowest digit in base b; repeat with q.

Binary grouping

16 = 2^4 and 8 = 2^3

One hex digit equals 4 bits and one octal digit 3 bits.

N
the integer to write
b
the base (2 to 36)
d_i
the digit at place i (0 to b − 1)
q, r
quotient and remainder of the division by b

Example: 500 ÷ 16 = 31 remainder 4; 31 ÷ 16 = 1 remainder 15 (F); 1 ÷ 16 = 0 remainder 1. Reading the remainders from bottom to top, 500 = 1F4 in hexadecimal.

Use cases

Web colours

Decode a #RRGGBB code into three decimal values from 0 to 255, or the other way round.

Unix permissions

Read an octal chmod mode as a sequence of r, w and x bits.

Bit masks and addresses

Write a bit mask, read a memory value or understand a binary field.

Computer science and maths classes

Check number-system exercises or compare the representations of one integer.

Examples

255 in hexadecimal

255 = 15 × 16 + 15, the largest value of one byte.

Input

255 (base 10)

Result

FF in hexadecimal, 11111111 in binary, 377 in octal

Orange CSS colour

FF = 255 (red), 88 = 136 (green), 00 = 0 (blue): rgb(255, 136, 0).

Input

FF8800 (base 16)

Result

16746496 in decimal

chmod 755

7 = 111 (rwx), 5 = 101 (r-x), 5 = 101 (r-x): rwxr-xr-x.

Input

755 (base 8)

Result

111101101 in binary, 493 in decimal

Grouped byte

Spaces are ignored, and each group of 4 bits gives one hex digit.

Input

1010 1010 (base 2)

Result

AA in hexadecimal, 170 in decimal

Base 36

1000 = 27 × 36 + 28, with R = 27 and S = 28.

Input

1000 (base 10)

Result

RS in base 36

Tips and best practices

  • Quick link: 16 = 2^4, so one hex digit is exactly 4 bits (FF = 1111 1111).
  • A byte has 8 bits: 00 to FF in hex, 0 to 255 in decimal.
  • Bases above 16 use letters up to Z; input accepts upper and lower case.
  • For numbers with a fractional part, convert the integer and fractional parts separately with a dedicated tool.
  • Check a conversion by converting back: you should recover the starting number.

Sources and references

Frequently asked questions

How do I convert decimal to binary?

Divide by 2, note the remainders, and read them from bottom to top. For example 13 gives 1101: 13 = 6 × 2 + 1, 6 = 3 × 2 + 0, 3 = 1 × 2 + 1, 1 = 0 × 2 + 1.

How do I convert hexadecimal to decimal?

Multiply each digit by a power of 16. FF = 15 × 16 + 15 = 255, and 1F4 = 1 × 256 + 15 × 16 + 4 = 500.

Which bases are supported?

All integer bases from 2 to 36, including binary (2), octal (8), decimal (10), hexadecimal (16) and base 36 (digits 0-9 then A-Z).

Can I convert negative or fractional numbers?

Negatives are accepted with a minus sign and shown with their sign (−42 gives −101010), without two's complement. Fractional numbers are not accepted.

Is there a size limit?

Not in practice: the calculation uses arbitrary-size integers. 2^64 − 1 = 18446744073709551615 gives FFFFFFFFFFFFFFFF.

Related tools

Tools similar or complementary to this one.

Similar tools

Convert a color between HEX, RGB, and HSL with equivalent values.

Mathematics & calculationUse this tool

Encode text as Base64 or decode a Base64 string back to its original content.

Mathematics & calculationFeaturedUse this tool

Write a number in words in English, French, Spanish, German, Italian or Portuguese, or turn written words back into digits.

Mathematics & calculationFeaturedUse this tool