r/AskComputerScience • • Sep 02 '26

How does a computer know between the number 65 and the letter H?

I'm watching CS50, and about halfway through week 0, doctor malen mentioned how 65 bits of data equals the letter H and i'm curious to that if 65 equal H, how does the company know the difference between H and just the number 65?

32 Upvotes

77 comments sorted by

View all comments

65

u/soundman32 Sep 02 '26

It doesnt.  There are many different encoding schemes going back to the dawn of computing.  65=H is just the ASCII 7-bit encoding definition.  The computer has no idea that we decided that for some cases the number 65 should end up onscreen as a capital H. 

Encodings like Unicode use 16 or 32 bit values (so they can use non Latin characters more easily), older computers may use Petscii (CBM 8 bit micros) or EBCDIC (IBM mainframes).  

6

u/pgetreuer Sep 02 '26 edited Sep 02 '26

Nit: This is otherwise accurate, but to pick a nit, "Unicode" itself does not specify the serialization. There are multiple encodings of Unicode, where the UTF (Unicode Transformation Format) family of encodings are standard.

UTF-16 encodes each Unicode codepoint (= one letter or symbol, usually) as one or two 16-bit code units in a variable-length scheme.

UTF-32 uses a fixed 32 bits per codepoint.

There's also UTF-8, which is very common. And more esoterically there's UTF-7 and UTF-EBCDIC.

ETA: D'oh, and as Mistakelndividual690 pointed out, ASCII code 65 (decimal) is "A," not "H." How'd we all miss that =)

3

u/alphaglosined Sep 03 '26

Unicode does specify the use of UTF, but like many aspects of Unicode, it's very much up to users choice on their willingness to follow the recommendations.

Text can be horrible like that.

2

u/ysth Sep 03 '26

There's also UCS-2 which is limited to 2 bytes per character. Leading to the surrogate character where a character that doesn't fit is broken into 2 characters. And LE and BE variants of all of those (except UTF-8). And cases where multiple Unicode characters represent a single displayed thing (glyph), like emojis.

2

u/iamparky Sep 04 '26 edited Sep 04 '26

UTF-EBCDIC is certainly esoteric; I doubt anybody's ever used it for anything serious. I happened to work for IBM in the late nineties, on the mainframe version of a somewhat well known piece of IBM software - and implemented Unicode support. Even there, in a team that was immensly proud of its mainframe heritage, I was told not to bother adding UTF-EBCDIC. I'm not sure it even had a codepage number.

1

u/Interesting_Debate57 Sep 03 '26

64 is all zeros underneath, that's the trick.

It also explains everything over 127.

2

u/[deleted] Sep 02 '26

[removed] — view removed comment

1

u/soundman32 Sep 02 '26

The OS (or the graphics card itself on older systems) has a translation table that says "when the code says display 0x41, display this collection of bits" that you recognise as the letter 'B'.  

If the display is purely bitmapped, then the display manager will take the character value, and draw a glyph in the font you've told it.  There is nothing intrinsic about 0x41=B.

1

u/Altruistic-Rice-5567 Sep 03 '26

And it's just software that decides what the bits mean. When you call print() function it is there that "well... this 65 really means H so I'll tell the screen to display an H" happens.