<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="webpost.xsl"?>
<post>
    <title>Data on a computer</title>
    <date>18 October 2021</date>
    <p>
        A few tools that can express almost anything.
    </p>

<p>
    Under the hood, computers access <q>memory.</q>
    Memory, in computing jargon<note>
        Computer jargon is mostly based on English, not Latin.
        <q>Memory</q> is computer jargon for a particular class of ways
        of creating a gargantuan list of bytes.
        When speaking with someone about computing in English
        I might say <q>my memory's not what it once was; how large was memory, again?</q> and assume they can tell
        that the first <q>memory</q> in that phrase was English
        while the second was jargon.
        This can be confusing to newcomers to the field.
    </note>, is a gargantuan list of bytes.
    Very early in computer design, different hardware used different size bytes,
    but today all of them use octets.
    An octet is a number between 0 and 255 (inclusive).
    Computer hardware has built-in commands to access several consecutive octet as if they were a multi-digit base-256 number:
    for example, [103][221] = 103*256+221 = 26,586.
    They also have built-in ways to treat numbers as signed integers
    (e.g., treating a two-octet number as a value between −32,768 and 32,767 instead of as a value between 0 and 65,535)
    or as non-integer numbers
    (using something like scientific notation).
</p>
<p>
    Note that we've already mentioned many possible meanings of a single octet.
    Maybe it's a number in its own right;
    maybe it's the first digit in a larger number, or the second digit in a larger number, and so on;
    and maybe that number should be left as is, or treated as a signed integer, or treated as a non-integer.
    How does the computer know which one to do?
    We tell it.
</p>
<p>
    Computers follow instructions we give them,
    and there are different instructions for each of these interpretations.
    I can tell the computer <q>go to position 39,048,452 in the list of octets called <q>memory</q> and read four octets as a non-integer number.</q>
    I can also tell it <q>go to position 39,048,454 in memory and read two octets as a non-negative integer.</q>
    There are two octets (those as positions 39,048,454 and 39,048,455) that both of these instructions will access,
    and will interpret in different ways.
    It is hard to come up with a scenario where I'd want to read the same octets as representing two different kinds of things,
    but that's on me, the programmer, to figure out:
    the computer just blindly does what I tell it to do.
</p>
<p>
    In computing jargon,
    the way we read a particular sequence of octets
    is called their <q>type</q><note>
        Again, <q>type</q> is jargon.
        What if I need to talk about different types of types?
        The jargon for that is <q>kinds of types</q>,
        and then <q>sorts of kinds of types</q>,
        though needing to talk about sorts of kinds of types
        is rare enough I've only used that jargon a few times in my life.
    </note>.
    We often want more types than just numbers,
    and have established a small number of approaches to getting more types:
    indirection, enumeration, consecutiveness, and adjacency.
</p>
<p>
    Indirection works by storing not the value itself
    but rather the position in memory where the value can be found.
</p>
<p>
    Enumeration works by defining a mapping between numbers and some other concept.
    One of the best known of these is ASCII
    which maps single octet numbers to things needed to run a digital typewriter.
    For example, 10 means <q>go down one line</q>;
    13 means <q>go to the beginning of the current line</q>;
    65 through 90 mean <q>type a capital letter</q> with A = 65, B = 66, and so on up to Z;
    97 through 122 type lower-case letters;
    and so on.
</p>
<p>
    Consecutiveness lets us make lists of things
    by the simple expedient of placing each item in the list's octets
    at consecutive locations in memory.
    We have two techniques for knowing how many things are in the list:
    we can have the length be a known value stored outside the list itself
    or we can use a special <q>end of list</q> value.
    ASCII, for example, uses 0 to mean <q>end of list</q>
    so that we can encode the entire list of actions we want a typewriter to do, regardless of how long that list is,
    and execute it by the following simple rule:
</p>
<clike>
    if octet in current position is 0 { stop } otherwise { tell the typewriter to do the thing this octet represents; move to the next position }
</clike>
<p>
    Combined with indirection, this means we can process arbitrarily long typeable content as a single number:
    the location in memory where we can find the start of the typeable content's ASCII encoding.
    That, in turn, means I can make a list of typeable things
    by placing those starting locations (which in computer jargon are called <q>pointers</q>) adjacently.
    And I can operate on this rapidly:
    for example, if I use 4-octet numbers for each pointer
    and want to learn the 8<sup>th</sup> typing action
    of the 382<sup>nd</sup> typeable thing,
    then I read a 4-octet number at a location 4 × 382 = 1528 octets after the start of my list,
    add 8 to that and use it as a memory location to read a 1-octet value,
    which I then interpret as ASCII.
</p>
<p>
    Adjacency is like consecutiveness in that it stores several things next to one another in memory,
    but it lets them each be their own type.
    For example, I could store a list of numbers of any length
    using two numbers stored next to one another in memory:
    the length of the list and a pointer to the list's first value.
    I could store person in a simplified genetic family tree
    using a pointer to a list of characters representing their name,
    several numbers representing their birth date,
    and two more pointers, one to the person providing the egg and the other to the person providing the sperm that jointly became this person.
</p>
<p>
    That is it.
    Virtually all data in all computers everywhere
    is made up of numbers,
    some interpreted as pointers or enumerates,
    combined consecutively or adjacently.
    There's no law limiting data to this,
    and every once in a while you'll bump into an outlier type
    like the the bitvector and the heapified array that uses some fifth technique,
    but the vast majority of data types,
    and by extension data itself,
    is just these few components carefully assembled.
</p>

</post>
