Binary to Hexadecimal Converter
Convert binary to hexadecimal by grouping bits into nibbles, with a step-by-step nibble table and fractional binary support
By Waqar Mushtaq · Last updated:
This converter turns a binary number into hexadecimal the way you'd do it by hand: split the bits into groups of four (nibbles) starting at the binary point, then replace each group with its hex digit. It shows every nibble with the padding zeros it needed, the result as a 0x code literal and in decimal, and -- for a raw bit pattern -- the same value zero-extended to 8, 16, 32, and 64 bits, the way it would appear in a register or memory dump. It works on inputs of any length without rounding, and converts binary fractions too (1101.101 = D.A).
How Binary to Hex Conversion Works
O(n) in bitsBecause 16 is a power of two, each hex digit maps to exactly one 4-bit group
The value of one nibble (0-15) is its hex digit (0-F)
Since 16 = 2⁴, every hexadecimal digit stands for exactly four binary digits, so no arithmetic on the whole number is needed -- just regrouping.
- Group the bits into fours, starting at the binary point. Move left for the whole-number part and right for the fraction.
- Pad the outermost groups with zeros so each has four bits: add leading zeros on the left end, trailing zeros on the right end of a fraction. Neither changes the value.
- Replace each group with its hex digit using the table: 0000 = 0, 1001 = 9, 1010 = A, ... 1111 = F.
Example -- 101101: Group from the right: 10 | 1101 → pad to 0010 | 1101 → 2 | D = 0x2D (45 in decimal)
Example -- 11010110.1011: 1101 | 0110 . 1011 → D | 6 . B = D6.B (214.6875 in decimal)
Example with a fraction that needs padding -- 1.1: 0001 . 1000 → 1.8 -- the fraction's last group gets trailing zeros, so .1 in binary is .8 in hex, not .1.
Going the other way, hex to binary is the same table read backwards: write each hex digit as four bits.
Use Cases
Reading Registers and Bit Fields
Datasheets describe hardware registers bit by bit, but code and debuggers show them in hex. Grouping the bits into nibbles makes it easy to see which hex digit a given flag lives in.
Writing Constants and Bitmasks
A mask like 1111 0000 0000 1111 is hard to read and easy to mistype in binary; 0xF00F is the same value in four characters. The standard-widths table gives you the zero-padded form for a uint8, uint16, uint32, or uint64 constant.
Memory Dumps, Colors, and Network Data
Hex dumps, MAC and IPv6 addresses, and CSS colors (#RRGGBB) all use two hex digits per byte. Converting a byte from binary shows exactly which bits each pair of digits encodes.
Computer Science Coursework
Check homework and exam answers for binary-to-hex conversions, including fractional values -- the nibble breakdown shows the working, not just the answer.
Frequently Asked Questions
How do you convert binary to hexadecimal?
Split the binary number into groups of four bits, starting from the right (or from the binary point), adding leading zeros to the leftmost group if needed. Then replace each 4-bit group with its hex digit: 0000-1001 become 0-9 and 1010-1111 become A-F. For example, 11011110 → 1101 1110 → DE.
Why does each hex digit equal four bits?
Because 16 = 2⁴. Four bits can hold 2⁴ = 16 different values (0-15), which is exactly the number of hex digits (0-9 and A-F). That one-to-one match is why hex is the standard shorthand for binary in computing -- one byte (8 bits) is always exactly two hex digits.
What is a nibble?
A nibble is a group of 4 bits -- half a byte. Each nibble corresponds to one hexadecimal digit, so a byte like 1010 0101 is two nibbles, A and 5, written 0xA5.
How do I convert a binary fraction to hex?
Group the bits after the binary point into fours moving right, and pad the last group with trailing zeros. 0.101 becomes 0.1010 = 0.A in hex. Unlike decimal fractions, every binary fraction converts to a finite hex fraction, so the result is always exact.
What does the 0x prefix mean?
It marks a number as hexadecimal in C, C++, Java, JavaScript, Python, and most other languages, so 0x10 means sixteen rather than ten. Some contexts use other markers instead -- a trailing h in assembly (10h), a # in CSS colors, or a subscript 16 in math (10₁₆).
Does converting to hex change negative or two's complement numbers?
Hex is just a shorter way to write the same bits, so a two's complement pattern converts nibble by nibble like any other: 1111 1111 is 0xFF whether it means 255 or −1. To see what a bit pattern means as a signed number, use the Binary to Decimal Converter.
Methodology
The formula above is implemented as a standalone module covered by unit tests, so its worked examples are re-checked on every change to the site. It is verified against the authoritative sources listed below.
Maintained by Waqar Mushtaq. Spotted a result that looks wrong? Report it and it becomes a failing test.