Skip to main content
  1. /classes/
  2. Classes, Fall 2026/
  3. CS 2010 Fall 2026: Course Site/

cs2010 Notes: 09-16 Text

·880 words·5 mins·

Characters
#

  • ASCII = 7 bit, A = 65, a = 97, 1 = 49, . = 46 (python ord)
  • We really use 8 bits, per character:
    • Top bit 0: rest is an ascii code
    • Top bit 1: multi-byte character, non-ascii

History intro:

  • We don’t strictly need to know any of this.
  • But it’s a good example of two key ideas about computing:
    • Sometimes apparently simple things are complicated.
    • Things are frequently the way they are for historical reasons. Computing is sometimes as much archaeology as engineering or math.

Long version:

  • Our modern 7-bit ASCII character set was finalized in 1965.
  • You’re typing Swedish and want to describe “en båt”?
  • In addition to variant Latin characters, a bunch of other languages have distinct alphabets (or stuff like abugidas that can be treated like alphabets)
    • Cyrillic
    • Greek
    • Arabic
    • Hebrew
    • 12 Brahmic scripts
    • Japanese has two distinct syllabifies = 92 characters (if we ignore Kanji for a moment)
    • etc
    • Each of these got their own 1 byte character set.
  • Standardizing this is easy. Just list all the alphabets and we’ll give each one its own block of characters. There aren’t that many alphabets so 2^16 = 64k should be enough letters for everyone. The international Unicode project started working on this in 1987.
  • Korean Hangul:
    • Each character represents one syllable. It’s constructed out of two / three sound pieces (jamo).
    • There are 51 jamo, so that’d fit fine in one byte.
    • So a character takes 3 bytes.
    • But there are only 11,292 combinations that get used, each of which renders as a distinct glyph.
    • That fits in two bytes.
    • So Korea first invented their own 2-byte encoding, and then took up 1/6th of the entire Unicode space.
  • Chinese:
    • A character is basically a word.
    • Chinese characters are also used in Korean and Japanese, and there are some Chinese characters that really only exist in the other languages.
    • So the CJK block (separate from Hangul) adds another 20k characters, or 1/3 of the 16-bit space.
  • Korean and Chinese are the two big ones, so major modern languages fit in 16 bit.

So, problem solved, 16 bit, and Microsoft Windows 95 and the Java programming language shipped assuming characters are 16 bits.

  • In English, 16 bits per character is twice what ASCII would take.
  • For common text-based formats like HTML, the text tends to be English or ASCII characters (e.g. <html><tags>).
  • The 16-bit space was basically full, but some rare-but-existing and mostly-historical languages got missed.
  • Turns out that storing historical text is useful too, so people want historical character support.

So the Unicode group expanded to a 32-bit encoding.

New mess in 1998:

  • Linux / UNIX / C code assume 8 bits per character.
  • Windows / Java code assume 16 bits per character.
  • The native Unicode characters are now 32 bits.
    • And they immediately added Emoji, which everyone wants.
  • So Ken Thomson invented UTF-8:
    • ASCII characters are 1 byte, first bit 0. Max efficiency for English and English-based stuff like HTML.
    • Other alphabets are typically 2 bytes.
    • CJK / Hangul characters are 3 bytes.
    • Rare / Historical characters or Emoji are 4 bytes.

Text
#

Text is a series of bytes.

  • For English keyboard chars, each byte is one character.
  • So the text “Hi, Welcome to CS 2010” is 22 bytes.

Structure of a Computer
#

  • CPU
  • RAM
  • Disk
  • I/O: Keyboard, screen, network

Where do we store data?
#

  • Running program: in RAM
  • Longer than one program? On disk, in a file.
  • A file is a series of bytes, with a name (short text)

Demonstrate file <-> bytes and different UI modes
#

  • Use gedit to create sample file
  • Use nemo to show properties:
    • Name
    • Size in bytes

Two user interface modes:

  • GUI, like gedit/nemo
    • gives a single clear view
    • common actions are visual and discoverable
    • Less common actions are hidden or entirely missing
    • Show space free in nemo
    • System monitor
  • CLI, repeat with echo/ls/stat/vim/duf/free -h
    • “we can do better than point and grunt: language”
    • communicate with text: commands and command output
    • Need to know the language(s), both concepts and grammar
    • hd (FILE)
    • man ascii
    • Absolutely need to read some docs.
  • Option 3: Natural language
    • opencode - Gemma
    • “Create a text file named ‘hello.txt’ containing the lyrics of Twinkle Twinkle Little Star”
    • What are the ascii codes for the characters in the file?
    • Append a snowman emoji to the end of the file.
    • Still need to know the concepts, although but there’s some improved discoverability through discussion.

File System Structure
#

  • We need to store files
    • That’s a sequence of bytes
    • And some metadata: Name, maybe file type, dates, etc.
  • Early computers just said your files go on a disk
    • Doesn’t work with too many files
    • We get this file cabinet metaphor, almost.
    • One document is a “file”, they go in “folders”, folders live on “disks”.
  • Technical detail: paths
    • Every file or directory has a path
      • One string of characters
      • On Linux/Mac, starts with “/”
      • On Windows, starts with a drive letter (probably C: for local)
    • Sequence of parts separated by / or \.
    • If we’re finding a file, the last part is the file name.
    • The rest of the parts are directory names.
  • Relative paths:
    • Every running program (including file managers and terminal windows) has a working directory.
    • Explain ./ and ../
Nat Tuck
Author
Nat Tuck