Conversions for 0–16
| 十进制Decimal | 二进制Binary | 八进制Octal | 十六进制Hexadecimal |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 1 | 1 | 1 | 1 |
| 2 | 10 | 2 | 2 |
| 3 | 11 | 3 | 3 |
| 4 | 100 | 4 | 4 |
| 5 | 101 | 5 | 5 |
| 6 | 110 | 6 | 6 |
| 7 | 111 | 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 | 10000 | 20 | 10 |
| 255 | 11111111 | 377 | FF |
Common ASCII codes
ASCII has 128 code points (0–127): 0–31 and 127 are non-printable control codes, and 32–126 are printable. Three anchors are worth memorising: uppercase A is 65, lowercase a is 97 (a difference of 32), and the digit 0 is 48. Any letter follows from there — K is 65 + 10 = 75 and k is 97 + 10 = 107. Chinese characters are outside ASCII entirely, which is why they always break on a pure-ASCII system.
| 十进制Dec | 十六进制Hex | 字符Character |
|---|---|---|
| 9 | 09 | Tab(制表符)Tab |
| 10 | 0A | LF(换行)LF (line feed) |
| 13 | 0D | CR(回车)CR (carriage return) |
| 32 | 20 | 空格Space |
| 33 | 21 | ! |
| 34 | 22 | " |
| 36 | 24 | $ |
| 37 | 25 | % |
| 38 | 26 | & |
| 40 | 28 | ( |
| 41 | 29 | ) |
| 42 | 2A | * |
| 43 | 2B | + |
| 44 | 2C | , |
| 47 | 2F | / |
| 48 – 57 | 30 – 39 | 数字 0 – 9Digits 0 – 9 |
| 58 | 3A | : |
| 61 | 3D | = |
| 63 | 3F | ? |
| 64 | 40 | @ |
| 65 – 90 | 41 – 5A | 大写 A – ZA – Z (uppercase) |
| 91 – 96 | 5B – 60 | [ \ ] ^ _ ` |
| 95 | 5F | _ |
| 97 – 122 | 61 – 7A | 小写 a – za – z (lowercase) |
| 123 – 126 | 7B – 7E | { | } ~ |
| 127 | 7F | DEL(删除)DEL (delete) |
想批量转换时用 进制转换工具 或 编码转换工具,别手算长串。For bulk work, use the base converter or the encoding converter instead of doing it by hand.
Converting by hand
Decimal to binary: divide repeatedly by 2, keep the remainders, read them in reverse — 156 becomes 10011100. Binary to decimal: expand by place value, where the nth bit from the right (starting at 0) carries weight 2ⁿ, so 1010 = 8 + 2 = 10. Binary to hexadecimal is the easiest: four bits make exactly one hex digit, so 1010 1111 is A F, namely 0xAF, and three bits at a time gives octal. Keep the weights 8-4-2-1 in mind and hex-to-binary takes seconds.
Notations and prefixes
Different contexts write the same value differently: 0xAF (hex in C-family languages and JavaScript), 0b1010 (a binary literal in some languages), 0o17 or 017 (octal — note that a leading zero is an octal trap in older code), \x41 (a string escape meaning A), %41 (hex inside URL encoding), and A or A (an HTML entity meaning A). Base64 is a different matter: it maps binary into 64 characters six bits at a time for transport rather than encryption, and anyone can reverse it — never use it to protect sensitive data.
ASCII is not Unicode
ASCII covers only 128 code points, whereas Unicode is a character set (assigning every character a code point, such as U+56FE for 图) and UTF-8 is one of its encodings: ASCII-range characters still take one byte, common Chinese characters take three, and emoji usually take four. GBK is a separate encoding where a Chinese character takes two bytes and is incompatible with UTF-8 — open a GBK file as UTF-8 and you get mojibake. Debug in this order: establish the file’s real encoding, then what the reader declares, and fix whichever side is wrong. Databases and APIs also need utf8mb4, or emoji get truncated or rejected.
FAQ
What is 255 in hexadecimal?
FF, that is 0xFF, because 255 = 15 × 16 + 15 and 15 is written F. It is the largest unsigned value a single byte can hold, so it shows up in masks and colour values such as #FFFFFF.
Why does hexadecimal need the 0x prefix?
To distinguish bases: 10 is ten in decimal while 0x10 is sixteen. C-family languages set the convention and JavaScript follows; octal’s 0o17 and the older leading-zero form invite confusion, so prefer 0o in new code.
How does Chinese mojibake happen?
Reading bytes encoded one way as if they were another — opening GBK text as UTF-8, or the reverse. The fix is to standardise on one encoding (UTF-8 is the sensible choice) and declare it consistently in files, databases and APIs.