ASCII 50
Digit 2 (2)
Printable ASCII
The digit two. ASCII code 50. Digits 0-9 occupy the contiguous range 48-57, so you can validate a digit with c >= '0' && c <= '9' and get its value with c - '0'.
Common uses & context
The character '2' — the digit 2 — has ASCII code 50 (0x32), not 2. This offset of exactly 48 between a digit's glyph and its numeric value is the single most common beginner trap in low-level text handling: the byte that draws '2' on screen is 50, while the number 2 is a different value entirely. The digit two. ASCII code 50. Digits 0-9 occupy the contiguous range 48-57, so you can validate a digit with c >= '0' && c <= '9' and get its value with c - '0'.
The ten digit characters '0'–'9' occupy the contiguous range 48–57, which makes digit handling cheap and branch-free. You can test whether a byte is a digit with c >= '0' && c <= '9', and recover its numeric value with c - '0' (equivalently c - 48). Parsing a whole number is then just value = value * 10 + (c - '0') for each character left to right. For '2', that means c - '0' yields 2.
All encodings at a glance
| Decimal | 50 |
| Hexadecimal | 0x32 |
| Octal | 0062 |
| Binary | 00110010 |
| HTML numeric entity | 2 |
| URL encoding | %32 |
| UTF-8 bytes | 0x32 |
Code snippets
JavaScript
String.fromCharCode(50); // "2"
50.toString(16); // "32"Python
chr(50) # '2'
ord(chr(50)) # 50
hex(50) # '0x32'HTML
2 <!-- numeric entity (no named entity for this character) -->Programming notes
- ▸Character-to-value: '2' - '0' = 2 (i.e. 50 - 48).
- ▸Digit test: c >= '0' && c <= '9' works because 0–9 are the contiguous codes 48–57.
- ▸Multi-digit parse step: value = value * 10 + (c - '0').
Frequently asked questions
What character is ASCII code 50?
ASCII code 50 is the character '2' (Digit 2). In hexadecimal it is 0x32, in octal 0062, and in binary 00110010.
What is 0x32 in ASCII?
Hexadecimal 0x32 equals decimal 50, which is the character '2' (Digit 2). To convert hex to ASCII yourself, read the two hex digits as a base-16 number (0x32 = 50) and look up that code point.
How do I write the character with code 50 in code?
In JavaScript use String.fromCharCode(50); in Python use chr(50); in HTML use the numeric entity 2. In a URL it is percent-encoded as %32, and in UTF-8 it is stored as the byte sequence 0x32.
Why is the digit '2' stored as 50 instead of 2?
Because '2' is a text character, not the number 2. Its ASCII code is 50; the numeric value 2 is separate. Subtract 48 (the code of '0') to convert the character to its value: '2' − '0' = 2.