Skip to content

Binary and hex converter

Convert between binary, decimal, hex and octal.

Convert
Bit width
Sign

Fits in

    Uses the Sign setting above. The examples beside each width are what that size is commonly used for.

    Conversions run in your browser with BigInt, so even 64-bit values stay exact. The page does not send what you type anywhere; the site counts page views.

    How do binary, octal and hex work?

    A binary and hex converter rewrites one number in another base: type it in binary, octal, decimal or hex and the other boxes update at once. All four are place-value systems, like the decimal numbers you already use. In decimal, the digits of 211 stand for 2 hundreds, 1 ten and 1 one. In binary, each place is worth double the one to its right (1, 2, 4, 8, 16 and so on), and each digit is 0 or 1. Eight bits make a byte.

    1 128 1 64 0 32 1 16 0 8 0 4 1 2 1 1 1101 = 13 = hex D 0011 = 3 = hex 3 128 + 64 + 16 + 2 + 1 = 211 = 0xD3
    The byte 11010011. Only the highlighted places are added up, and each group of four bits is one hex digit.

    Hex (base 16) and octal (base 8) exist because they are shorthand for binary. One hex digit is exactly four bits, so a byte is always two hex digits, which is why colors (#D3A05B), memory addresses and checksums are written in hex. One octal digit is three bits; you meet it mostly in Unix file permissions such as 755.

    What are the powers of two?

    Powers of two are the place values of binary. These are exact; the 64-bit row is the largest a 64-bit counter can reach plus one.

    Powers of two
    PowerDecimal valueHex
    2^0 1 1
    2^1 2 2
    2^2 4 4
    2^3 8 8
    2^4 16 10
    2^5 32 20
    2^6 64 40
    2^7 128 80
    2^8 256 100
    2^10 1,024 400
    2^12 4,096 1000
    2^16 65,536 10000
    2^20 1,048,576 100000
    2^24 16,777,216 1000000
    2^32 4,294,967,296 100000000
    2^48 281,474,976,710,656 1000000000000
    2^64 18,446,744,073,709,551,616 10000000000000000

    Source: calculated with exact integer arithmetic.

    Which digits does hex use?

    Hex borrows the letters A to F for the values 10 to 15. Memorize this small table and every hex number becomes readable.

    Hex digits
    HexDecimalBinary (4 bits)
    0 0 0000
    1 1 0001
    2 2 0010
    3 3 0011
    4 4 0100
    5 5 0101
    6 6 0110
    7 7 0111
    8 8 1000
    9 9 1001
    A 10 1010
    B 11 1011
    C 12 1100
    D 13 1101
    E 14 1110
    F 15 1111

    Source: Hexadecimal, Wikipedia; values calculated.

    How do you convert decimal to binary?

    Divide by 2 again and again and write down the remainders. Read them from the last one back to the first.

    1. Divide 211 by 2: quotient 105, remainder 1.
    2. Divide 105 by 2: quotient 52, remainder 1.
    3. Divide 52 by 2: quotient 26, remainder 0, then 26 gives 13 (0), 13 gives 6 (1), 6 gives 3 (0), 3 gives 1 (1), 1 gives 0 (1).
    4. Read the remainders from the bottom: 11010011.

    To go to hex, split the binary into groups of four from the right (1101 0011) and look each group up in the table above: D and 3, so 0xD3.

    What is two's complement?

    Computers need negative numbers too, and almost all of them store them as two's complement. The left-most bit keeps its place value but counts as negative: in 8 bits it is worth −128 instead of +128. That one change makes addition and subtraction use the same circuit, and there is only one zero.

    Worked example: −5 in 8 bits

    Start with 5: 00000101. Flip every bit: 11111010. Add 1: 11111011. Check by place values: −128 + 64 + 32 + 16 + 8 + 2 + 1 = −5. In hex that is 0xFB. Click the Signed switch above, type −5 in the decimal box and the cells show the same pattern.

    Unsigned range by width
    BitsValues
    8 bits 0 to 255
    16 bits 0 to 65,535
    32 bits 0 to 4,294,967,295
    64 bits 0 to 18,446,744,073,709,551,615

    Source: calculated: 0 to 2^n − 1.

    Signed (two’s complement) range by width
    BitsValues
    8 bits -128 to 127
    16 bits -32,768 to 32,767
    32 bits -2,147,483,648 to 2,147,483,647
    64 bits -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

    Source: calculated: −2^(n−1) to 2^(n−1) − 1.

    The same pattern means different numbers depending on how you read it: 11111111 is 255 unsigned and −1 signed. The converter keeps the bits and changes only the reading when you flip the switch.

    How is text stored as bytes?

    Text becomes numbers first (each character has a code point) and then bytes. The web uses UTF-8, which writes the first 128 characters, the old ASCII range, as one byte each and uses 2 to 4 bytes for everything else.

    UTF-8 byte lengths
    Code pointsBytesExample
    U+0000 to U+007F 1 A is 41
    U+0080 to U+07FF 2 é is C3 A9
    U+0800 to U+FFFF 3 € is E2 82 AC
    U+10000 to U+10FFFF 4 😀 is F0 9F 98 80

    Source: RFC 3629, UTF-8.

    ASCII excerpt
    CharacterDecimalHexBinary
    Space 32 20 00100000
    0 48 30 00110000
    9 57 39 00111001
    A 65 41 01000001
    Z 90 5A 01011010
    a 97 61 01100001
    z 122 7A 01111010
    ~ 126 7E 01111110

    Source: ASCII, RFC 20 and Wikipedia; values calculated.

    So "Hi" is 48 69 in hex or 01001000 01101001 in binary. Capital and lowercase letters differ by exactly 32, one bit: A is 01000001 and a is 01100001. Switch the converter to Text and paste something with an accent or emoji to see the extra bytes. To encode those bytes as text for email or JSON, use our Base64 encoder and decoder.

    Common mistakes

    • Mixing up the reading. 0x80 is 128 as an unsigned byte but −128 as a signed one.
    • Dropping leading zeros. They do not change the value, but 0001 and 1 are different widths, which matters in protocols and masks.
    • Trusting a 53-bit calculator. Ordinary JavaScript numbers lose exactness past 9,007,199,254,740,991; this tool uses BigInt so a 64-bit value stays exact. For everyday arithmetic, our scientific calculator is the better fit.
    • Treating text length as byte length. "café" is 4 characters but 5 bytes in UTF-8.

    Common questions

    How do I convert binary to decimal?

    Add the place values of the bits that are 1. For 1101 that is 8 + 4 + 1 = 13. Type it in the binary box and the decimal box shows it. Timestamps are decimal counts of seconds too; our Unix timestamp converter turns them into dates.

    Why is hex used instead of binary?

    It is four times shorter and each digit maps to exactly four bits, so nothing is lost converting back and forth.

    What happens if my number does not fit the width?

    Typing a bigger value widens the cells automatically up to 64 bits. If you pick a narrower width yourself, the extra high bits are cut off and a note says so.

    Can it handle numbers above 64 bits?

    The four boxes can, because they use BigInt. The cells show only the lowest 64 bits.

    Which prefix does each base use?

    0b for binary, 0o for octal and 0x for hex in most programming languages. You can type them or leave them out.

    Sources

    Last reviewed November 9, 2026.