Binary, Hex, and Octal Conversion Cheat Sheet
Convert binary, hexadecimal, octal, and decimal with grouping rules, worked examples, lookup tables, Unix permissions, two's complement, and bitwise tips.
Reading time
10 min
Binary, hexadecimal, octal, and decimal are different notations for the same integer value. Binary uses 2 digits, octal uses 8, decimal uses 10, and hexadecimal uses 16. The fastest conversions exploit their bit grouping: one hex digit maps to 4 bits, and one octal digit maps to 3 bits.
That relationship is why developers use hex for bytes, addresses, masks, and dumps, while octal survives in Unix permission modes. This cheat sheet covers the conversions worth doing by hand, the mistakes worth avoiding, and the point where a tool is safer than mental arithmetic.
Number base quick reference
| Base | Name | Digits | Common prefix | One digit represents |
|---|---|---|---|---|
| 2 | Binary | 0–1 |
0b |
1 bit |
| 8 | Octal | 0–7 |
0o |
3 bits |
| 10 | Decimal | 0–9 |
none | A power of 10 |
| 16 | Hexadecimal | 0–9, A–F |
0x |
4 bits, or one nibble |
Modern JavaScript accepts 0b, 0o, and 0x prefixes. MDN's current numeric literal guide warns that a leading zero without 0o is legacy octal syntax and can fail in strict mode. Other languages have their own parsing rules, so treat the prefix as part of the input format—not decoration.
Values worth recognizing
| Decimal | Binary | Octal | Hex |
|---|---|---|---|
| 0 | 0000 |
0 |
0 |
| 1 | 0001 |
1 |
1 |
| 2 | 0010 |
2 |
2 |
| 3 | 0011 |
3 |
3 |
| 4 | 0100 |
4 |
4 |
| 5 | 0101 |
5 |
5 |
| 6 | 0110 |
6 |
6 |
| 7 | 0111 |
7 |
7 |
| 8 | 1000 |
10 |
8 |
| 9 | 1001 |
11 |
9 |
| 10 | 1010 |
12 |
A |
| 11 | 1011 |
13 |
B |
| 12 | 1100 |
14 |
C |
| 13 | 1101 |
15 |
D |
| 14 | 1110 |
16 |
E |
| 15 | 1111 |
17 |
F |
| 16 | 1 0000 |
20 |
10 |
Three anchors solve many debugging checks:
0xF=15=1111₂;0xFF=255=1111 1111₂, one full byte;0x100=256=1 0000 0000₂, the first value needing 9 bits.
How positional notation works
Each digit is multiplied by a power of the base. The rightmost digit uses power 0, the next uses power 1, and so on.
For binary 101101₂:
1×2⁵ + 0×2⁴ + 1×2³ + 1×2² + 0×2¹ + 1×2⁰
= 32 + 0 + 8 + 4 + 0 + 1
= 45
For hexadecimal 0x2F:
2×16¹ + 15×16⁰
= 32 + 15
= 47
For octal 755₈:
7×8² + 5×8¹ + 5×8⁰
= 448 + 40 + 5
= 493
Positional expansion is universal. It is the reliable fallback when grouping shortcuts do not apply.
Binary to hexadecimal: group 4 bits
Start at the right and split the binary value into groups of four. Pad the leftmost group with zeros if necessary, then translate each group using the lookup table.
Convert 11010110₂:
1101 0110
D 6
= 0xD6
Convert 1011011₂:
0101 1011
5 B
= 0x5B
Leading zero padding changes the display width, not the value. 0x5B, 0x05B, and 0x005B all represent decimal 91 when interpreted as unsigned integers. Width becomes important later when the bits represent a fixed-size field, signed integer, protocol value, or memory word.
Hexadecimal to binary: expand each digit
Replace every hex digit with exactly four bits. Preserve leading zeros when the source width matters.
Convert 0x3AF:
3 A F
0011 1010 1111
Convert a 32-bit mask 0x0000000F:
0000 0000 0000 0000 0000 0000 0000 1111
Dropping the leading zeros still gives value 15, but it loses the fact that the mask was represented in a 32-bit field.
Binary to octal: group 3 bits
Start at the right and split into groups of three. Pad the leftmost group, then translate each group to one octal digit.
Convert 11010110₂:
011 010 110
3 2 6
= 326₈
The shortcut works because octal is 2³. Every octal digit maps exactly to three binary digits.
Octal to binary: expand each digit
Replace every octal digit with three bits:
7 5 5
111 101 101
This mapping explains numeric Unix permissions. GNU Coreutils documents that the read, write, and execute permissions for each class occupy three bits, so one octal digit represents each class. Its official numeric mode reference maps:
- read =
4=100₂; - write =
2=010₂; - execute/search =
1=001₂.
Therefore:
| Mode | Owner | Group | Others |
|---|---|---|---|
644 |
read + write | read | read |
755 |
read + write + execute | read + execute | read + execute |
700 |
all three | none | none |
600 |
read + write | none | none |
Special mode bits can add a fourth octal digit. Do not infer safe permissions from a memorized slogan; confirm the intended access and platform behavior before changing a production path.
Decimal to binary: repeated division by 2
For a positive integer, divide by 2, record the remainder, and repeat with the quotient. Read the remainders from bottom to top.
Convert decimal 156:
| Division | Quotient | Remainder |
|---|---|---|
| 156 ÷ 2 | 78 | 0 |
| 78 ÷ 2 | 39 | 0 |
| 39 ÷ 2 | 19 | 1 |
| 19 ÷ 2 | 9 | 1 |
| 9 ÷ 2 | 4 | 1 |
| 4 ÷ 2 | 2 | 0 |
| 2 ÷ 2 | 1 | 0 |
| 1 ÷ 2 | 0 | 1 |
Reading upward gives 10011100₂.
For mental conversion, subtract descending powers of two instead:
156 = 128 + 16 + 8 + 4
= 2⁷ + 2⁴ + 2³ + 2²
= 10011100₂
Decimal to hexadecimal: repeated division by 16
Divide by 16, record each remainder, and translate remainders 10–15 to A–F.
Convert decimal 2026:
| Division | Quotient | Remainder |
|---|---|---|
| 2026 ÷ 16 | 126 | 10 = A |
| 126 ÷ 16 | 7 | 14 = E |
| 7 ÷ 16 | 0 | 7 |
Reading upward gives 0x7EA.
For byte-oriented values, converting decimal to binary and regrouping into nibbles can be easier because it keeps the bit layout visible.
Signed integers: the same bits can mean different values
Number base conversion alone does not tell you whether a fixed-width value is signed. The bit pattern 1111 1111 has these interpretations:
- unsigned 8-bit integer: 255;
- signed 8-bit two's-complement integer: −1;
- hex representation of either bit pattern:
0xFF.
Width is essential. In two's complement, an n-bit unsigned pattern u is interpreted as:
signed = u, when the top bit is 0
signed = u - 2ⁿ, when the top bit is 1
For 0xFE in 8 bits:
unsigned = 254
signed = 254 - 256 = -2
For 0xFFFE in 16 bits, the signed result is also −2. Same low pattern, different declared width.
BitLens has a separate signed view for 8-, 16-, 32-, and 64-bit interpretations. Use it when a dump, register, or protocol field has a defined width; do not guess from the number of visible digits if leading zeros may have been omitted.
Bitwise operations cheat sheet
For corresponding bits A and B:
| A | B | AND | OR | XOR |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 | 1 |
| 1 | 0 | 0 | 1 | 1 |
| 1 | 1 | 1 | 1 | 0 |
Common uses:
value & masktests or keeps selected bits;value | masksets selected bits;value ^ masktoggles selected bits;~valueflips bits, but the result depends on the chosen width;value << nshifts left and may discard high bits in a bounded field;value >> nshifts right, with signedness and language rules affecting fill behavior.
Example with 8-bit values:
0xAC = 1010 1100
0x0F = 0000 1111
AND = 0000 1100 = 0x0C
OR = 1010 1111 = 0xAF
XOR = 1010 0011 = 0xA3
BitLens masks its bitwise results to the selected 8-, 16-, 32-, or 64-bit width and shows which bit positions changed.
Common conversion mistakes
Confusing a value with its representation
255, 0xFF, 377₈, and 11111111₂ are the same unsigned value. A prefix, suffix, or surrounding protocol determines the notation.
Dropping significant width
0x01 and 0x0001 have the same integer value but may describe different field widths. Preserve padding when debugging serialized data.
Assuming hex implies unsigned
Hex displays bits compactly. It does not define signedness. Interpret the pattern using the declared width and integer encoding.
Treating byte order as digit order
The hex value 0x12345678 is a number. A little-endian byte sequence for that 32-bit value may appear in memory as 78 56 34 12. Normalize byte order before converting a memory dump.
Running floats through an integer converter
The hex encoding of an IEEE 754 float is a bit pattern, not the ordinary base-16 spelling of its decimal value. Use a float decoder. The companion guide explains the IEEE 754 floating-point format.
Using a language's ordinary number type for large integers
Some languages cannot represent every large integer exactly in their default numeric type. In JavaScript, use BigInt when integer precision matters beyond the safe Number range. BitLens's main binary/octal/decimal/hex converter uses BigInt for integer conversion.
A practical BitLens workflow
- Open the Convert tab and enter the value in its known base.
- Preserve or choose grouping by nibble or byte.
- Check bit length, set-bit count, parity, and power-of-two status.
- Use Signed when a fixed-width two's-complement interpretation is possible.
- Use Bitwise for masks, shifts, and width-bounded results.
- Use Float only when the bits encode IEEE 754 binary32 or binary64.
- Use ASCII when the value may represent a character or Unicode code point.
The extension requests no host permissions. Conversion happens locally, and the context-menu action operates on text you explicitly select. See what browser extension permissions can access and the current privacy details for the boundary.
This local processing model follows the broader reason we build local-first browser extensions: a number converter does not need a server copy of a memory value, mask, or code point.
Number base conversion FAQ
Why does one hex digit equal four binary digits?
Hexadecimal has 16 possible digits, and 16 = 2⁴. Four bits also have 16 possible patterns, from 0000 to 1111.
Why does one octal digit equal three binary digits?
Octal has 8 digits, and 8 = 2³. Three bits have 8 possible patterns, from 000 to 111.
Is 0x10 equal to decimal 10?
No. 0x10 is hexadecimal 16. Decimal 10 is hexadecimal 0xA.
Is 010 octal or decimal?
It depends on the language and parser. Avoid ambiguous leading-zero notation. Use 0o10 for octal in modern JavaScript and other languages that support that explicit prefix.
How do I convert a negative decimal number to hex?
First determine the required bit width and signed representation. Under 8-bit two's complement, −1 is 0xFF; under 16-bit two's complement, it is 0xFFFF. “Negative hex” without width is ambiguous.
What is the fastest way to convert binary to hex?
Group bits into sets of four from the right, pad the left group, and map each nibble directly to one hex digit.
Keep the value, width, and interpretation separate
Most conversion bugs come from answering only “what number is this?” A correct debugging answer also records the base, bit width, signedness, byte order, and data type.
Filed underbinary hex octal conversionnumber base conversionhexadecimalbinarybitlens
● More from the journal
- 01
Why Your Downloaded Tracks Need ID3 Tags and Artwork (and How to Get Them Automatically)
A downloaded track without metadata is just a mystery file. Here's what an ID3 tag actually contains, why it matters more than it seems, and how to get it embedded automatically instead of by hand.
TutorialAugust 20, 2026 - 02
How to Export a Full SoundCloud Playlist as MP3/AAC
Downloading a SoundCloud playlist track-by-track doesn't scale past a handful of songs. Here's how to export an entire playlist in one action, with order, quality, and per-track metadata intact.
TutorialAugust 20, 2026 - 03
Best Chrome Extensions for DJs and Music Curators in 2026
DJs and serious music curators end up running a browser-based workflow whether they plan to or not. Here's a practical toolkit for discovery, evaluation, archiving, and organization — and where each tool actually earns its place.
ListicleAugust 20, 2026