Công Cụ Nhanh

Number base converter

Accepts negatives (-42), fractions (10.5), the 0x / 0b / 0o prefixes; spaces and _ are ignored.

  • Binary (2)
    1111 1111
  • Octal (8)
    377
  • Decimal (10)
    255
  • Hexadecimal (16)
    FF
  • 73

Two's complement (signed)

Width
8-bit binary
1111 1111
8-bit hex
FF
Read as unsigned
255
Read as signed
-1

Signed range: -128 to 127; unsigned: 0 to 255.

Text ↔ binary / hex (UTF-8)

Text ↔ binary / hex (UTF-8)

9 bytes

Processed in your browser. Your files and data are never uploaded to a server.

Quick answer

To convert decimal to binary, keep dividing by 2 and read the remainders from bottom to top: 13 → 1101. To go back, multiply each digit by 2 to the power of its position and add: 1101 = 8 + 4 + 0 + 1 = 13. Hex uses 0–9 and A–F, and each hex digit is exactly 4 bits.

What is a number base?

Type a number in any base to see it instantly in binary, octal, decimal, hexadecimal and a custom base from 2 to 36. The tool uses BigInt, so numbers hundreds of digits long stay exact, and it accepts negatives, fractions (10.5) and the 0x, 0b and 0o prefixes. The two's complement panel shows how a negative number is stored in 8, 16, 32 or 64 bits, and the text panel turns characters (including accented letters) into UTF-8 binary or hex and back.

Illustration of an abacus frame with three rows of beads grouped in twos, eights and sixteens, beside small square tiles showing on and off like bits

How to convert a number to another base

  1. 1

    Type the number into “Number to convert” and pick its base under “From base” (choose “Other base” for base 3, 5, 36…).

  2. 2

    Read the results: binary and hex are grouped in 4 digits for readability; “Copy” copies the number without spaces.

  3. 3

    For negative numbers or raw register values, choose 8, 16, 32 or 64 bits in the two's complement panel to see the bit pattern and the signed value.

  4. 4

    To turn text into machine codes, use “Text ↔ binary / hex”; switch direction to decode bytes back into text.

0–15 in each base

DecimalBinaryOctalHex
0000000
1000111
2001022
3001133
4010044
5010155
6011066
7011177
81000108
91001119
10101012A
11101113B
12110014C
13110115D
14111016E
15111117F

Swipe sideways to see the whole table →

One hex digit = 4 bits and one octal digit = 3 bits, so converting between binary and hex is just grouping 4 digits from the right.

Integer ranges by bit width

WidthSigned (two's complement)UnsignedCommon types
8 bit−128 to 1270 to 255byte, int8, uint8
16 bit−32,768 to 32,7670 to 65,535short, int16
32 bit−2,147,483,648 to 2,147,483,6470 to 4,294,967,295int, int32, MySQL INT
64 bitabout ±9.22 × 10¹⁸0 to about 1.84 × 10¹⁹long, int64, BIGINT

Swipe sideways to see the whole table →

Real-world examples

CSS colours

#FF8800 is three hex pairs FF, 88 and 00: red 255, green 136, blue 0. Enter FF in base 16 to see 255.

Linux permission 755

755 is octal: 7 = 111 (rwx) and 5 = 101 (r-x). Converting 755 from base 8 to binary gives 111 101 101.

Reading a negative sensor value

A 16-bit register returns 0xFF38. Enter FF38 in base 16 and pick 16 bits in two's complement: the signed value is −200.

Accented letters in UTF-8

“é” takes 2 bytes, C3 A9 (11000011 10101001), while plain English letters take 1 byte, so accented text is longer in bytes.

Common mistakes

“Not a valid digit”.
Check “From base”: 19 does not exist in base 8 (digits 0–7 only) and the letter A only exists from base 11 upwards.
0.1 in binary is extremely long.
0.1 in base 10 is a repeating fraction in base 2 (like 1/3 = 0.333… in base 10). The tool cuts it at 32 digits; this is also why 0.1 + 0.2 ≠ 0.3 in code.
A negative number in binary just gets a minus sign.
That is the mathematical notation. Computers store negatives in two's complement: see the two's complement panel with your data type's bit width.

How do you convert a fraction to another base?

The whole part is converted by repeatedly dividing by the new base. The part after the point works the other way: multiply by the new base, take the whole part as the next digit and repeat with what is left. For 0.75 in binary: 0.75 × 2 = 1.5 → 1; 0.5 × 2 = 1.0 → 1; the result is 0.11.

A fraction that ends in one base may repeat forever in another. 0.5 and 0.25 are short in binary, but 0.1 and 0.2 repeat endlessly, which is why computers store them approximately.

Glossary

Base (radix)
How many distinct digits a system uses: base 10 has ten, base 2 has just 0 and 1.
Bit
One binary digit, either 0 or 1.
Byte
A group of 8 bits holding 256 values (0–255), written as two hex digits.
Two's complement
How computers store negative integers: the top bit is the sign and addition works the same for negative and positive numbers.
UTF-8
The most common text encoding on the web; each character takes 1–4 bytes.
BigInt
JavaScript's arbitrary-length integer type, which is never rounded the way Number is.

Frequently asked questions

Why do programmers use hexadecimal?

Hex is four times shorter than binary and converts to it digit by digit, so a byte is always exactly two hex digits (00–FF).

How is two's complement calculated?

Invert every bit of the positive number and add 1. For −5 in 8 bits: 5 = 00000101 → inverted 11111010 → plus 1 = 11111011 (0xFB).

What is the largest base?

36, using 10 digits and 26 letters. Base 36 is handy for short IDs such as order codes or short links.

Are large numbers rounded?

No. The tool uses BigInt, so whole numbers of any length keep every digit, unlike a pocket calculator or JavaScript's Number (exact only to about 16 digits).

How do I convert hex to decimal by hand?

Multiply each digit by 16 to the power of its position from the right (starting at 0) and add them up. For example 2F = 2 × 16 + 15 = 47.

Does text to binary use ASCII?

The tool uses UTF-8. For English letters, digits and punctuation UTF-8 is identical to ASCII; accented letters and emoji need more bytes.

Ratings and comments

Loading…