BinaryHex

Spaces and 0b are fine

Try
Hex
3D6
Decimal 9823 hex digits · 10 bitsPadded with 2 leading zeros to fill the first group

Digit by digit

Bits are grouped in 4s from the right
  1. 00113
  2. 1101D
  3. 01106
Guide

How to convert binary to hex

  1. Remove spaces and any 0b prefix.
  2. Split the bits into groups of 4, starting from the right. If the leftmost group is short, pad it with zeros.
  3. Replace each group with its hex digit from the table below.

Worked example

Converting 101111. It has 6 bits, so it's padded with 2 zeros to make full groups of 4:

4 bitsHex digit
00102
1111F

101111 → 0x2F

  • Always group from the right. Grouping from the left gives the wrong answer when the number of bits isn't a multiple of 4.
  • Hex is a short way to write binary: 32 bits fit in just 8 hex digits.
  • Add a 0x prefix to mark a number as hex in most programming languages.

Hex digits in binary

4 bits per digit
HexBinaryDecimal
000000
100011
200102
300113
HexBinaryDecimal
401004
501015
601106
701117
HexBinaryDecimal
810008
910019
A101010
B101111
HexBinaryDecimal
C110012
D110113
E111014
F111115
Learn

Binary to hex conversion explained

Grouping bits in fours, padding, prefixes and why programmers write binary as hex.

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:

  • 0x80 in C, C++, Java, JavaScript, Python, Go, Rust and most other languages.
  • #FF8000 for colors in CSS and design tools.
  • 80h in some assembly languages, or $80 in others.
  • \x80 for 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 0b prefix. 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.

FAQ

Frequently asked questions

Quick answers about the binary to hex converter and how it works.

How do I convert binary to hex?

Split the bits into groups of 4 starting from the right, then replace each group with its hex digit. 101111 becomes 10 1111, then 0010 1111, which is 2F.

Why group from the right?

The rightmost bit is always the ones place, so grouping from the right keeps each group lined up with one hex digit's place value. Grouping from the left gives a wrong answer whenever the number of bits isn't a multiple of 4.

What if the number of bits isn't a multiple of 4?

The leftmost group is padded with zeros. That doesn't change the value. The tool shows the added zeros in the digit-by-digit view.

Should hex be uppercase or lowercase?

Either. 2F and 2f mean the same thing. Use the Uppercase switch to match the style you need.

Can I add the 0x prefix?

Yes. Turn on Add 0x prefix to get a value like 0x2F, ready to paste into most programming languages.

What happens with a negative binary number?

The minus sign carries over, so -101111 becomes -2F. To convert a two's complement pattern, enter the bit pattern itself without a sign: 11111111 gives FF.

Still have a question?Contact us