ASCII 52
Digit 4 (4)
Printable ASCII
The digit four. ASCII code 52. In hexadecimal the digit 4 is still 4, but letters A-F (codes 65-70) extend the range — see code 65 for the uppercase A used in hex.
Common uses & context
The character '4' — the digit 4 — has ASCII code 52 (0x34), not 4. 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 '4' on screen is 52, while the number 4 is a different value entirely. The digit four. ASCII code 52. In hexadecimal the digit 4 is still 4, but letters A-F (codes 65-70) extend the range — see code 65 for the uppercase A used in hex.
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 '4', that means c - '0' yields 4.
All encodings at a glance
| Decimal | 52 |
| Hexadecimal | 0x34 |
| Octal | 0064 |
| Binary | 00110100 |
| HTML numeric entity | 4 |
| URL encoding | %34 |
| UTF-8 bytes | 0x34 |
Code snippets
JavaScript
String.fromCharCode(52); // "4"
52.toString(16); // "34"Python
chr(52) # '4'
ord(chr(52)) # 52
hex(52) # '0x34'HTML
4 <!-- numeric entity (no named entity for this character) -->Programming notes
- ▸Character-to-value: '4' - '0' = 4 (i.e. 52 - 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 52?
ASCII code 52 is the character '4' (Digit 4). In hexadecimal it is 0x34, in octal 0064, and in binary 00110100.
What is 0x34 in ASCII?
Hexadecimal 0x34 equals decimal 52, which is the character '4' (Digit 4). To convert hex to ASCII yourself, read the two hex digits as a base-16 number (0x34 = 52) and look up that code point.
How do I write the character with code 52 in code?
In JavaScript use String.fromCharCode(52); in Python use chr(52); in HTML use the numeric entity 4. In a URL it is percent-encoded as %34, and in UTF-8 it is stored as the byte sequence 0x34.
Why is the digit '4' stored as 52 instead of 4?
Because '4' is a text character, not the number 4. Its ASCII code is 52; the numeric value 4 is separate. Subtract 48 (the code of '0') to convert the character to its value: '4' − '0' = 4.