binaryasciibitdata-representationbit-representation

ASCII table and character presentation


We learn in class about ASCII table, and that every character from 128 characters has a unique number from 0-128 representing it. For example "a" is 97 (in binary 97 is 1100001). "%" is 37 (and in binary 37 is 0100101). (I understand that for a fixed length of 7 we should allow the binary number start with 0)

If 97 is representing "a", then what represents the string "97"? What represents the integer 97?


Solution

  • I think your question is based on the notion that, given a representation of an integer, string or other type of value, you can decern the type and the value. You can't.

    In most digital computer architectures, data is bits, accessed in contiguous 8-bit bytes. You can take a byte, think of it as a non-negative integer, and represent it in binary, octal, decimal, hexadecimal, …. Binary is used when a bit represents a value by itself. Hexadecimal is preferred for its compactness and easy translation to binary. Decimal is used when the whole byte has some cardinal number value to humans, which makes it the choice for negative integers.

    So, given the byte, 97 (decimal), say from a 1-byte file or at a memory address, what's the type and value? The only way to know is through some sort of shared understanding: an agreement, declaration, convention, specification, data map, etc. In other words, communication. Complete communication consists of the data and accompanying or separate metadata that indicates how to interpret the bytes.

    97₁₀ = 61₁₆ = 01100001₂ could be:

    So, rephrasing your question as: What's the difference 97 representing "a" and 97 representing the integer 97? The answer is in the metadata, not the bytes.