DevKits

ASCII 49

Digit 1 (1)

Printable ASCII

The digit one. ASCII code 49. Subtract 48 (or '0') to get its numeric value. Often confused with the lowercase letter l and uppercase I in monospaced fonts, which is why some fonts add a serif or slash to distinguish them.

Common uses & context

The character '1' — the digit 1 — has ASCII code 49 (0x31), not 1. 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 '1' on screen is 49, while the number 1 is a different value entirely. The digit one. ASCII code 49. Subtract 48 (or '0') to get its numeric value. Often confused with the lowercase letter l and uppercase I in monospaced fonts, which is why some fonts add a serif or slash to distinguish them.

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 '1', that means c - '0' yields 1.

All encodings at a glance

Decimal49
Hexadecimal0x31
Octal0061
Binary00110001
HTML numeric entity&#49;
URL encoding%31
UTF-8 bytes0x31

Code snippets

JavaScript

String.fromCharCode(49); // "1"
49.toString(16); // "31"

Python

chr(49)           # '1'
ord(chr(49))      # 49
hex(49)           # '0x31'

HTML

&#49;   <!-- numeric entity (no named entity for this character) -->

Programming notes

  • Character-to-value: '1' - '0' = 1 (i.e. 49 - 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 49?

ASCII code 49 is the character '1' (Digit 1). In hexadecimal it is 0x31, in octal 0061, and in binary 00110001.

What is 0x31 in ASCII?

Hexadecimal 0x31 equals decimal 49, which is the character '1' (Digit 1). To convert hex to ASCII yourself, read the two hex digits as a base-16 number (0x31 = 49) and look up that code point.

How do I write the character with code 49 in code?

In JavaScript use String.fromCharCode(49); in Python use chr(49); in HTML use the numeric entity &#49;. In a URL it is percent-encoded as %31, and in UTF-8 it is stored as the byte sequence 0x31.

Why is the digit '1' stored as 49 instead of 1?

Because '1' is a text character, not the number 1. Its ASCII code is 49; the numeric value 1 is separate. Subtract 48 (the code of '0') to convert the character to its value: '1' − '0' = 1.

Nearby codes

Encode & convert this character