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.
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.
Bits (click a bit to flip it, most significant first)
16-bit unsigned value
49,374
0xC0DE
uint16_t value = 0xC0DEu;Byte order in memory
| Address offset | +0 | +1 |
|---|---|---|
| Big-endian | C0 | DE |
| Little-endian | DE | C0 |
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.
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.
A signed N-bit value uses the same bits, with the top bit counted as negative:
That is the same as subtracting 2^N whenever the top bit is set. Negation follows directly:
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.
+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.
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.
One hex digit is one nibble. Memorize these and most conversions become reading.
| Hex | Binary | Decimal |
|---|---|---|
| 0 | 0000 | 0 |
| 1 | 0001 | 1 |
| 2 | 0010 | 2 |
| 3 | 0011 | 3 |
| 4 | 0100 | 4 |
| 5 | 0101 | 5 |
| 6 | 0110 | 6 |
| 7 | 0111 | 7 |
| 8 | 1000 | 8 |
| 9 | 1001 | 9 |
| A | 1010 | 10 |
| B | 1011 | 11 |
| C | 1100 | 12 |
| D | 1101 | 13 |
| E | 1110 | 14 |
| F | 1111 | 15 |
Limits of the exact-width C types, which are the same limits as any two’s complement register of that size.
| Bits | Signed minimum | Signed maximum | Unsigned maximum | Unsigned maximum (hex) |
|---|---|---|---|---|
| 8 | -128 | 127 | 255 | 0xFF |
| 16 | -32,768 | 32,767 | 65,535 | 0xFFFF |
| 32 | -2,147,483,648 | 2,147,483,647 | 4,294,967,295 | 0xFFFFFFFF |
| 64 | -9,223,372,036,854,775,808 | 9,223,372,036,854,775,807 | 18,446,744,073,709,551,615 | 0xFFFFFFFFFFFFFFFF |
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.
| Hex | Binary | Unsigned | Signed |
|---|---|---|---|
| 0x00 | 0000 0000 | 0 | 0 |
| 0x01 | 0000 0001 | 1 | 1 |
| 0x7F | 0111 1111 | 127 | 127 |
| 0x80 | 1000 0000 | 128 | -128 |
| 0x81 | 1000 0001 | 129 | -127 |
| 0xFE | 1111 1110 | 254 | -2 |
| 0xFF | 1111 1111 | 255 | -1 |
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.
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.
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.
Add the power of two for every 1 bit. 1101 0110 is 128 + 64 + 16 + 4 + 2 = 214 as an unsigned number.
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.
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.
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.
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.
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.
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.
See all free electronics tools →
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.
Free to start. No card required.