NewAI Part GeneratorFree to get started
FREE TOOL

Hex converter (binary, decimal, octal)

Type a number into this hex converter and read it in binary, decimal and octal at 8, 16, 32 or 64 bits, signed or unsigned. Any field takes input, so it works just as well as a binary to hex converter. You can also flip individual bits and read the byte order and the C literal for the same value.

Bit width
Read as

Bits (click a bit to flip it, most significant first)

B1
C0
B0
DE

16-bit unsigned value

49,374

0xC0DE

Unsigned
49,374
Signed (two’s complement)
-16,162
Bits set
8 of 16
Range of this type
0 to 65,535
C literal
uint16_t value = 0xC0DEu;

Byte order in memory

Address offset+0+1
Big-endianC0DE
Little-endianDEC0

How do you convert binary to hex?

Group the bits in fours from the right and replace each group with one hex digit, because 16 = 2⁴. For example 1101 0110 is 0xD6, which is 214 as an unsigned number and -42 as an 8-bit signed (two’s complement) number.

How a base converter works

Each base is the same positional sum with a different radix, so a hexadecimal to decimal converter and a binary to decimal converter run the same arithmetic. Hex and binary line up because one hex digit is exactly four bits; octal digits are three bits, so they do not line up with bytes.

value = Σ d_i × r^i
d_i
the digit at position i, counted from 0 at the right
r
the base: 2, 8, 10 or 16

A signed N-bit value uses the same bits, with the top bit counted as negative:

value = −b_(N−1) × 2^(N−1) + Σ b_i × 2^i     (i from 0 to N−2)
b_i
bit i, 0 or 1
N
the bit width

That is the same as subtracting 2^N whenever the top bit is set. Negation follows directly:

−x = (NOT x) + 1     signed value = pattern − 2^N, if the top bit is 1

Worked examples

Example 1: 1101 0110 in every base

The groups are 1101 = D and 0110 = 6, so the hex value is 0xD6. As an unsigned number it is 128 + 64 + 16 + 4 + 2 = 214. The top bit is set, so as an 8-bit signed number it is 214 − 256 = -42. In octal it is 326.

Example 2: −1000 as a 16-bit value

+1000 is 0000 0011 1110 1000 (0x03E8). Inverting every bit gives 1111 1100 0001 0111 (0xFC17), and adding one gives 0xFC18. The check: 65536 − 1000 = 64536, which is the unsigned reading of the same bits.

Example 3: 0xDEADBEEF in memory

Read as unsigned it is 3,735,928,559; read as a 32-bit signed number it is -559,038,737. A big-endian machine stores DE AD BE EF from the lowest address up, and a little-endian machine stores EF BE AD DE, which is what a hex dump of memory on an x86 or a typical Arm Cortex-M part shows.

Hex to binary and decimal table

One hex digit is one nibble. Memorize these and most conversions become reading.

HexBinaryDecimal
000000
100011
200102
300113
401004
501015
601106
701117
810008
910019
A101010
B101111
C110012
D110113
E111014
F111115

Integer ranges by bit width

Limits of the exact-width C types, which are the same limits as any two’s complement register of that size.

BitsSigned minimumSigned maximumUnsigned maximumUnsigned maximum (hex)
8-1281272550xFF
16-32,76832,76765,5350xFFFF
32-2,147,483,6482,147,483,6474,294,967,2950xFFFFFFFF
64-9,223,372,036,854,775,8089,223,372,036,854,775,80718,446,744,073,709,551,6150xFFFFFFFFFFFFFFFF

8-bit two’s complement values

The same pattern reads differently depending on the type you store it in. Set the tool to signed and it works as a two’s complement calculator at 8, 16, 32 or 64 bits.

HexBinaryUnsignedSigned
0x000000 000000
0x010000 000111
0x7F0111 1111127127
0x801000 0000128-128
0x811000 0001129-127
0xFE1111 1110254-2
0xFF1111 1111255-1

Where this goes wrong in real firmware

  • Integer promotion: uint8_t and uint16_t operands are promoted to int before arithmetic, so ~x on a uint8_t holding 0xF0 is 0xFFFFFF0F on a 32-bit int, not 0x0F. Cast or mask the result back to the width you meant.
  • Shifts on signed values: C11 6.5.7 gives no valid result for left-shifting a negative value or shifting into overflow, and leaves right-shifting a negative value up to the compiler. Do bit manipulation on unsigned types.
  • Narrowing to a signed type: converting a value that does not fit is implementation-defined (C11 6.3.1.3), even though nearly every compiler simply keeps the low bits.
  • Reading registers narrower than the variable: a 12-bit two’s complement sensor value in a 16-bit register needs sign extension. Subtract 4096 when bit 11 is set.
  • Casting a byte buffer to a wider pointer: the result depends on endianness and may be a misaligned access. Assemble values from bytes with shifts instead.

The calculator covers the standard widths of 8, 16, 32 and 64 bits. It treats integers only, so floating-point and fractional formats need a separate conversion.

Glossary

Bit width
How many bits a value occupies. It sets the range and the position of the sign bit.
Two’s complement
A signed integer encoding in which the top bit has weight −2^(N−1).
Sign extension
Copying the sign bit into the new upper bits when widening a signed value, which keeps the value the same.
Nibble
Four bits, exactly one hex digit.
Endianness
The order in which the bytes of a multi-byte value are stored or sent.
MSB and LSB
The most significant and least significant bit (or byte) of a value.

Frequently asked questions

How do you convert binary to hex?

Split the bits into groups of four from the right and replace each group with one hex digit. 1101 0110 becomes D6, so the number is 0xD6.

How do you convert hex to decimal?

Multiply each digit by its power of 16 and add. 0x2A is 2 × 16 + 10 = 42. Every field above updates as you type, so it works as a hex to decimal converter and a decimal to hex converter with no mode to switch.

How do you convert binary to decimal?

Add the power of two for every 1 bit. 1101 0110 is 128 + 64 + 16 + 4 + 2 = 214 as an unsigned number.

What is two’s complement?

The way nearly all hardware stores signed integers. The top bit counts as −2^(N−1) instead of +2^(N−1), so at 8 bits 0xFF is −128 + 127 = -1. To negate a number, invert every bit and add one.

What is the range of int8_t, int16_t, int32_t and int64_t?

An N-bit signed integer holds −2^(N−1) to 2^(N−1) − 1: -128 to 127, -32,768 to 32,767, -2,147,483,648 to 2,147,483,647, and -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.

What is the difference between big-endian and little-endian?

The order of the bytes in memory. 0x12345678 is stored as 12 34 56 78 on a big-endian system and 78 56 34 12 on a little-endian one, starting from the lowest address. The value is the same; only code that reads memory byte by byte can tell.

Why can’t I write -2147483648 directly in C?

The minus sign is an operator applied to the constant 2147483648, which does not fit in a 32-bit int, so the constant takes a wider type. stdint.h avoids this by writing (-2147483647 - 1). For INT64_MIN it is a real problem, because 9223372036854775808 fits no standard signed type.

Can I write binary literals in C?

The 0b prefix is part of C23 (WG14 proposal N2549). Before that it is a compiler extension, available in GCC and Clang, so hex is the portable choice in older code bases.

Why do other converters get large 64-bit values wrong?

JavaScript numbers and spreadsheet cells are 64-bit floats, exact only up to 2^53 − 1. This page uses arbitrary-precision integers, so 9,007,199,254,740,993 correctly converts to 0x0020000000000001.

More free PCB tools

See all free electronics tools →

Sources

Design the whole board, not one number

ProtoFlow is free AI PCB design software: describe a circuit and get a schematic with real parts, PCB layout with an autorouter, SPICE simulation and Gerber files. Native KiCad, Altium and EAGLE import and export. Free on macOS, Windows and Linux.

Get for Mac

Free to start. No card required.