"0" the character vs 0 the number — binary and text

corethe most common encoding confusion

Answer

00110000

Why this example is worth doing

The character 0 is encoded as 48, not as 0, and confusing the two is the single most common error when students first handle text as bytes. The page shows both bytes side by side and gives the conversion rule — subtract 48, or mask off the low four bits — which is exactly what a real parser does. It also notes that the digits were placed at 48 so that this masking trick works.

Try your own input in the Binary ⇄ text / ASCII. Convert text to binary and back, byte by byte, with the full UTF-8 breakdown.

How the answer is reached

ASCII encoding of 1 character

ASCII: one byte per character, the high bit always zero.

ASCII encoding of 1 character — columns character, code point, decimal, hex, binary, template
charactercode pointdecimalhexbinarytemplate
0U+00304830001100000xxxxxxx
Three different numbers; the UI must show all three — ASCII encoding of 1 character
countvalue
bytes1
code points1
UTF-16 code units1

Compare with

Open this example in the Binary ⇄ text / ASCII

The field arrives filled in with this example’s input.

Note:

Notation this page assumes

  • Bit strings are written most significant bit first, and bit 0 is the least significant bit.
  • A width is stated explicitly wherever it changes the answer; nothing is silently sign-extended or truncated.
  • ASCII is the 7-bit set padded to one byte; UTF-8 is shown byte by byte, so a non-ASCII character is more than eight bits.

Sources

  • ANSI X3.4 / ISO-IEC 646, the ASCII character set
  • The Unicode Standard, Annex on the UTF-8 encoding form