Long strings of 0s and 1s are hard to read, so programmers shorten them to hexadecimal. A binary to hex converter does that for you, with every hex digit standing for four bits. Paste any binary number above and you'll get its hex value instantly, with each group of four bits shown next to the digit it becomes. This guide covers how to convert binary to hex by hand, why the grouping always starts on the right, and how hex is written in code.
Why programmers write binary as hex
Binary is precise but hard to read. A 32-bit value is 32 digits long, and it's easy to lose your place or miscount. Hexadecimal packs the same information into 8 digits, and unlike decimal, it keeps a direct link to the bits: each hex digit always matches the same four bits. That's why memory addresses, color codes, error codes and bit masks are almost always written in hex. You get the readability of a short number without losing sight of which bits are set.
How to convert binary to hex
Start at the right-hand end of the binary number and split it into groups of four bits. If the leftmost group has fewer than four bits, pad it with zeros on the left. Then replace each group with its hex digit, from 0000 = 0 to 1111 = F. For example, 1101011010 has 10 bits. Grouping from the right gives 11 0101 1010, and padding the first group gives 0011 0101 1010. Those groups are 3, 5 and A, so the answer is 35A.
Why grouping starts on the right
The rightmost bit is always the ones place, so grouping from the right makes each group of four line up with one hex place value: ones, sixteens, 256s and so on. Grouping from the left only works when the number of bits is an exact multiple of four. Try it with 101111: grouping from the right gives 10 1111, which is 2F, or 47. Grouping from the left would give 1011 11, which reads as the wrong value. The padding zeros added on the left never change the number, just as writing 047 doesn't change 47.
Checking your answer
A quick way to check a binary to hex conversion is to convert both numbers to decimal. 1101011010 is 512 + 256 + 64 + 16 + 8 + 2 = 858, and 35A is 3 × 256 + 5 × 16 + 10 = 858, so the conversion is right. The binary to decimal converter shows the place values if you want to see the working, and the decimal value also appears under the result above.
Hex notation in different languages
Once you have the hex digits, you may need to mark them as hex so they aren't mistaken for decimal:
0x80in C, C++, Java, JavaScript, Python, Go, Rust and most other languages.#FF8000for colors in CSS and design tools.80hin some assembly languages, or$80in others.\x80for a single byte inside a string in many languages.
Turn on Add 0x prefix to get a value that's ready to paste into code. Hex letters can be upper or lower case. Both mean the same thing, and the Uppercase switch lets you match your project's style.
Bit masks and flags in hex
Hex makes bit patterns easy to recognize once you're used to it. 10000000, a byte with only its top bit set, is 0x80. 00001111, the low four bits, is 0x0F, and 11110000, the high four bits, is 0xF0. A byte with every bit set is 0xFF. Because each hex digit covers exactly four bits, you can tell which bits are set in a mask like 0x0F at a glance. To combine masks or test bits, try the AND, OR and XOR operations in the binary calculator.
Negative numbers
If you type a binary number with a minus sign, the sign carries over, so -101111 becomes -2F. That's the mathematical answer. In a computer, a negative number is usually stored as a two's complement bit pattern instead. To convert one, enter the pattern itself without a sign: 11111111 gives FF, which is −1 as a signed byte. The two's complement calculator shows how those patterns are formed.
Useful extras
- Paste binary with spaces, underscores or a
0bprefix. They're ignored. - Watch the digit-by-digit view to see the padding added to the first group.
- To expand hex back into bits, use the hex to binary converter.
- For groups of three bits instead of four, use the binary to octal converter.
Always group from the right. Starting from the left is the most common mistake, and it changes the answer whenever the number of bits isn't a multiple of four.