Hex to Binary Converter
Result
Binary
- Grouped in fours
- 0010 1010 0011 1111
A hex to binary converter rewrites a hexadecimal number in base two, and of all the conversions on this site it is the only one that needs no arithmetic at all. One hex digit is exactly four binary digits — that is not a coincidence of any particular number, it is the reason hexadecimal exists — so each character is replaced by its own four bits and nothing carries between them. 2 becomes 0010, A becomes 1010, 3 becomes 0011 and F becomes 1111, so 2A3F becomes 10101000111111. The substitution table has sixteen entries and never grows: 0 is 0000, 1 is 0001, and the sequence counts up in binary to F, which is 1111. Every character is worth four binary digits whatever its position, unlike decimal, where a digit's weight depends on where it sits. One detail is easy to trip over. The digits of the answer are printed twice, once as a plain run and once cut into groups of four, and the grouped line is longer because its first group has been padded out with leading zeros. 2A3F is fourteen bits long, so its grouped form is 0010 1010 0011 1111 — sixteen characters, with three zeros added at the front. Those zeros do not change the value; they exist so that the boundary between the second and third groups is visible rather than something you have to count out. Lowercase input is accepted and normalised: 2a3f and 2A3F are the same number and produce the same answer, which matters because hexadecimal strings in the wild — colour values, hashes, identifiers — are usually written in lowercase.
Each character of 2A3F expanded into its four binary digits
| Hex digit | Nibble | Decimal |
|---|---|---|
| 2 | 0010 | 2 |
| A | 1010 | 10 |
| 3 | 0011 | 3 |
| F | 1111 | 15 |
Four rows, one per character, and that is the entire method — there is no fifth row to add and no carry to explain. The third column is the character read as a number, which is the value the four bits in the second column add up to: A is ten because 1010 is 8 + 2, and F is fifteen because 1111 is 8 + 4 + 2 + 1. Reading the second column downwards and joining it gives the binary answer, and reading the third column is what you would do instead if the question had asked for decimal. The first row is the one to look at for the padding rule: 2 is 0010, with a leading zero that the number itself does not need, and that zero is there so this row is four characters wide like the other three. The table is fixed at 2A3F while the panel above converts whatever you typed.
Formula
2A3F ⇒ 2 → 0010, A → 1010, 3 → 0011, F → 1111 ⇒ 10101000111111, grouped as 0010 1010 0011 1111
- 2A3F
- The hexadecimal number to convert. Letters are case-insensitive, so 2a3f and 2A3F are the same value; the answer is always printed in uppercase, which is the convention for binary and hexadecimal notation on this site
- one character
- The unit this conversion works in. Each character is handled on its own, and nothing is carried from one to the next — which is why convert hex to binary can be done left to right, in any order, without keeping a running total
- 4 bits
- How many binary digits each character expands into, without exception. Sixteen possible characters and sixteen possible four-bit patterns is the whole reason the two bases pair up, and it means the length of the binary answer is always exactly four times the number of characters
- 0000 — 1111
- The complete set each character can produce, counting up in binary from 0 to 15. This is the substitution table written out: 0 is 0000, 1 is 0001, and the counting continues to 9 as 1001 and then A to F as 1010 to 1111
- ⇒ 10101000111111
- The digits joined up with nothing between them. This is the number's own binary form, and it is not padded: leading zeros are dropped, so a value whose top bits are zero comes out shorter than four times its characters
- 0010 1010 0011 1111
- The same digits cut into fours, and this one is padded — the first group is 0010 rather than 10, with three leading zeros added so that every group is four characters wide and the boundaries line up with the hexadecimal characters
- 2⁵³ − 1
- The ceiling on the input, and it arrives here in an unfamiliar shape: fourteen hexadecimal characters, which is 1FFFFFFFFFFFFF, which is fifty-three binary digits, which is 9007199254740991 in decimal. A longer input is refused rather than converted
Hexadecimal is what people write and binary is what machines execute, so moving between them is a daily step for anyone working close to the hardware. A colour code like 2A3F is four hexadecimal characters, and reading which bits of it are set — which is what a bitmask, a permission flag or a register setting actually asks — means seeing it in binary. Hashes, checksums and bit flags printed in hexadecimal are read the same way, and so are the addresses in a debugger or the flags in a packet capture. The conversion is worth doing in the other direction too, which is why it is a separate page: binary is unreadable past a handful of digits, so a value found in binary is normally written down in hexadecimal before being passed on. In coursework the task appears as convert hex to binary, and there is nothing to show in the way of working beyond a substitution — but the padding is worth writing out, because an answer like 10101000111111 and an answer like 0010 1010 0011 1111 are the same number with different amounts of visible structure, and which one is wanted depends on whether the reader needs the value or the byte layout.
Worked examples
Converting 2A3F
- Take the characters one at a time: 2, A, 3, F
- Replace each with its four bits: 2 is 0010, A is 1010, 3 is 0011, F is 1111
- Join the four groups with nothing between them: 10101000111111
- Cut the same digits into fours and pad the first group: 0010 1010 0011 1111
The default, and the example that shows the padding. The two output lines differ in length — fourteen digits against sixteen including the three spaces — and that is expected: the first line is the number, the second is the number with its character boundaries made visible. Note also that A and F are substituted, not converted; there is no arithmetic in any of these steps.
One byte, B2
- B is 11, which is 1011 in four bits
- 2 is 0010 in four bits
- Join them: 10110010 — eight digits, two groups, one byte
Two hexadecimal characters are always eight bits, which is one byte, and this is why the pairing is worth knowing: the width of a value is readable straight off without counting anything. The group boundaries here also fall on the byte in a useful way, which is a property of two characters rather than of this particular value.
Lowercase input, 2a3f
- Lowercase a counts the same as uppercase A: both are eleven
- Lowercase f counts the same as uppercase F: both are fifteen
- The conversion runs exactly as it did for 2A3F and gives the same answer
Both outputs come out word for word identical to the first example. Hexadecimal strings copied from a web page, a stylesheet or a log are usually lowercase, so accepting either case is not a convenience — refusing lowercase would make the page unusable on exactly the inputs people bring to it.
The largest input, 1FFFFFFFFFFFFF
- Fourteen characters, so the answer is fifty-six bits once the first group is padded
- The leading 1 is 0001 in a four-bit group, which is where the padding shows
- The thirteen F characters are each 1111, so the padded answer is fifty-three ones preceded by three zeros
- Without padding, the number itself is fifty-three ones
The ceiling, and the clearest case of the padding rule: the first group is 0001 rather than 1, so the grouped line has three leading zeros that the plain line does not. The same limit appears on the decimal pages as 9007199254740991 and on the reading pages as fifty-three digits — it is one boundary written in three bases.
Limitations
This page converts whole numbers only, and the input is a hexadecimal string rather than a decimal one, so there is no decimal point to reject: characters outside 0 to 9 and A to F are refused instead. The input may be at most fourteen hexadecimal characters, which is 1FFFFFFFFFFFFF, and a longer string is refused with a message rather than truncated — a truncated answer would look like an answer. Leading zeros are accepted and change nothing; a leading minus sign is accepted, and there the padding is applied to the digits before the sign is attached, so the grouped line reads minus 0010 rather than minus 1010 with a sign in the middle. The answer is always printed in uppercase regardless of how the input was written. The table below expands the default value 2A3F and does not follow what you typed. Going the other way, from binary back to hexadecimal, is a separate page, and this one does no arithmetic on the result.
Frequently asked questions
- Why is one hexadecimal digit always four binary bits?
- Because both four and sixteen are powers of two, and sixteen is four twos multiplied together. Four binary digits can be arranged in two to the fourth, which is sixteen, different patterns — exactly the number of characters base sixteen has to offer. So the two sets line up perfectly: every character has one four-bit pattern and every four-bit pattern has one character, with nothing left over on either side. That is why hexadecimal is used rather than, say, base ten, which does not divide into bits evenly.
- Why is the grouped answer longer than the plain one?
- Because the grouped line is padded and the plain line is not. The plain line is the number's own binary form, so it drops leading zeros; the grouped line has to be a whole number of four-bit groups, so it fills the top group out with zeros. For 2A3F that means three extra zeros at the front — fourteen digits in one line, sixteen in the other. Neither is wrong, and they are the same value. If you need the value, use the first; if you need to see where the characters fall, use the second.
- How do I convert hex to binary by hand?
- Replace each character with its four bits and join them up, working from left to right. The four bits for the ten digits are counting in binary — 0 is 0000, 1 is 0001, 2 is 0010, up to 9 which is 1001 — and then A is 1010, B is 1011, C is 1100, D is 1101, E is 1110 and F is 1111. There is nothing to carry and no running total to keep, so the characters can be done in any order.
- Does it matter whether I type the letters in upper or lower case?
- No. 2a3f and 2A3F are the same number and both convert to 10101000111111. The answer is always printed in uppercase, which is the usual convention for both bases in technical writing. Lowercase input is worth accepting because most hexadecimal strings people copy — a colour value from a stylesheet, a hash, an identifier from a log — are written that way.
- What is the largest hexadecimal number I can convert here?
- Fourteen characters: 1FFFFFFFFFFFFF is the ceiling, and it converts to fifty-three ones. Longer strings are refused with a message rather than shortened, and the limit is not specific to this page — it is the same boundary the decimal pages express as 9007199254740991 and the reading pages as fifty-three digits. At a wider value a machine can no longer hold neighbouring whole numbers apart, so an answer past it could not be trusted.
- Is converting hex to binary the same as converting hex to decimal?
- No, though they are easy to confuse because both start from the same string. Converting to binary is a substitution: each character becomes four bits and no arithmetic happens. Converting to decimal is a sum: each character is multiplied by the power of sixteen its position is worth — 2A3F is 2×4096 + 10×256 + 3×16 + 15 — and the terms are added. The binary page is faster because the base is a power of two and the decimal one is not.
References
- Hexadecimal — base sixteen, the letters A to F, and why one hexadecimal digit is exactly four binary digits — Wolfram MathWorld (United States)
- Binary number — positional notation, place values, and the powers of two that four-bit groups count through — Wolfram MathWorld (United States)
- Powers of two — the sequence 1, 2, 4, 8 … that a four-bit group spans from top to bottom, catalogued as OEIS A000079 — OEIS Foundation Inc. (United States)
- 教育部关于印发义务教育课程方案和课程标准(2022 年版)的通知——The fifth item in the annex list of this notice is the Mathematics Curriculum Standards for Compulsory Education (2022 edition); positional systems and conversion between different bases are part of the Number and Algebra strand of these standards, and the wording of the standards and the grade-band breakdown are governed by that annex — 中华人民共和国教育部