Computer Data Representation

In the context of computer organization, data representation refers to the methods used by computers to represent and store digital information such as numbers, characters, images, etc. All data within a computer is represented and stored in binary form, consisting of two digits: 0 and 1 (binary numbers).

Within a computer, different types of data utilize distinct representation schemes, as outlined below:

  1. Integer Representation: Integers in computers are typically represented using the Two's Complement system. The advantage of using complement notation is that it unifies addition and subtraction operations while eliminating the need to explicitly distinguish between positive and negative signs.
  2. Floating-Point Representation: Decimals in computers are usually represented as floating-point numbers, which consist of a mantissa (significand) and an exponent. This format allows for the representation of very large or very small real numbers while maintaining precision.
  3. Character Representation: Characters in computers are commonly represented using ASCII codes (American Standard Code for Information Interchange). The ASCII code maps characters to 8-bit binary numbers, allowing it to represent 128 different characters.
  4. Image Representation: Images in computers are typically represented either as bitmaps or vector graphics. Bitmaps use the color of individual pixels to depict an image, whereas vector graphics use mathematical formulas to define shapes and lines.

In addition to these data representation methods, there are others used within a computer, such as compression encoding and encryption coding. The method chosen for representing and storing data significantly impacts computer performance and functionality; therefore, it is essential to select appropriate data representations that meet the specific needs of the system.

Original Code, Inverse Code, and Two's Complement

Original Code (Sign-Magnitude)

Original code is a method using binary numbers to represent signed integers. It is the simplest and most direct representation scheme. In original code notation, the most significant bit (MSB) represents the sign: 0 indicates a positive number, and 1 indicates a negative number. For example, in an 8-bit original code system, 00000000 represents 0, 10000000 represents -0, 01111111 represents +127, and 11111111 represents -127.

The primary advantage of original code is its simplicity; it is easy to understand and implement. However, it also has certain drawbacks. The most significant issue is the inconvenience in handling addition and subtraction operations, as performing a subtraction between two identical numbers can potentially lead to overflow errors. For instance, calculating $3 - 5$: if represented in original code, 3 becomes 00000011 and -5 becomes 10000101. Subtracting them yields 10000010, which represents the original code for -2. However, mathematically, this result should be interpreted as the Two's Complement representation of -2 to facilitate correct arithmetic processing in hardware.

To address these issues, Inverse Code and Two's Complement notation were proposed:

  • Inverse Code: This method generates a negative number by keeping the sign bit unchanged while taking the complement (flipping bits) of all other digits relative to the original code.
  • Two's Complement: This is derived from the inverse code by adding 1 to the result. The resulting value represents the negative integer. Two's Complement notation can represent both negative numbers and zero, as well as positive integers; consequently, it has been widely adopted in computing systems.

Inverse Code

Inverse code is a method for representing signed binary numbers obtained by performing an inversion operation on original code. Similar to original code, the MSB represents the sign: 0 for positive, 1 for negative. For positive numbers, their inverse code remains identical to their original code. For negative numbers, the inverse code is derived by inverting all bits except the sign bit relative to the original code. In an 8-bit system using inverse code, 00000000 represents +0, 10000000 represents -127 (note: this differs from standard Two's Complement where MSB=1 and rest inverted+1), 01111111 represents +127, and 11111111 represents -0.

The advantage of inverse code is that it resolves the inconvenience associated with addition/subtraction in original code and is relatively easy to implement. However, a major drawback exists: there are two distinct representations for zero. Positive zero is represented as 00000000, while negative zero is represented as 10000000.

To resolve this ambiguity regarding the representation of zero, Two's Complement notation was introduced. In Two's Complement, the method for representing negative numbers remains consistent with inverse code (invert bits except sign bit), but positive numbers are handled differently: all bits are inverted and then 1 is added to the result. This scheme not only avoids the issues found in inverse code but also allows for a unified representation of negative numbers, zero, and positive integers; therefore, it has been widely adopted in computing systems (e.g., integer arithmetic in CPUs).

It should be noted that within Two's Complement notation, there is an edge case: for the minimum value of a signed number (such as -128 in an 8-bit system), its absolute magnitude cannot be directly represented because it exceeds the maximum representable positive value by one. In such scenarios, special handling methods are typically employed, such as overflow detection or truncation logic.

In summary, Two's Complement is a simple and effective method for representing signed integers that has found extensive application in modern computing architectures.

Computer Character Encodings

Character encodings (or codes) refer to the encoding schemes used within computers to represent characters, numbers, symbols, etc., typically utilizing binary code consisting of 0s and 1s. Common computer character encodings include:

  1. ASCII Code: A standard encoding scheme for English alphabetic text using a 7-bit binary format to encode 128 distinct characters (letters, digits, punctuation).
  2. Extended ASCII Code: An extension of the basic ASCII code that adds an extra bit, utilizing an 8-bit binary format to represent up to 256 characters, including additional symbols and extended Latin/Greek alphabets.
  3. Unicode Code: A universal character encoding standard (ISO/IEC 10646) capable of representing virtually all written languages worldwide using either a 16-bit or 32-bit binary format to cover text, symbols, graphics from various scripts and ideograms.
  4. UTF-8 Encoding: A variable-length character encoding based on Unicode that uses between 1 to 4 bytes per character depending on the complexity of the symbol, optimizing storage space while maintaining backward compatibility with ASCII.
  5. BCD Code (Binary-Coded Decimal): An encoding method for decimal numbers using a binary format where each digit is represented by four bits; e.g., the number '0' is encoded as 0000, and '1' as 0001.

Beyond these, there are other specific encodings such as Morse code, Gray code, Chinese character encoding (e.g., GBK, Big5), etc. Different encodings suit different application scenarios; selecting the appropriate one enhances system performance and efficiency.

Number Systems

In computer organization, a number system is a method of representing numbers using a finite set of symbols or digits. While humans commonly use the decimal system (base-10) with ten digits (0–9), computers utilize other bases such as binary (base-2), octal (base-8), and hexadecimal (base-16).

1. Decimal System

Decimal is the most common base in daily life, utilizing ten symbols: 0 through 9 to represent values. In decimal notation, each digit's position represents a power of ten; specifically, the $i$-th digit corresponds to $(10)^{i-1}$.

For example, the value "123" is calculated as:
$$1 \times 10^2 + 2 \times 10^1 + 3 \times 10^0 = 100 + 20 + 3 = 123$$

2. Binary System

Binary is the fundamental number system used internally by computers, composed exclusively of two digits: 0 and 1. All data within a computer is stored and processed in binary format. In this system, each digit's position represents a power of two; specifically, the $i$-th digit corresponds to $(2)^{i-1}$.

For example, the value "1011" is calculated as:
$$1 \times 2^3 + 0 \times 2^2 + 1 \times 2^1 + 1 \times 2^0 = 8 + 0 + 2 + 1 = 11_{10}$$

Since binary relies on only two digits, its bit width can be easily expanded to accommodate large numbers. This facilitates bitwise and logical operations, making it the most widely used system in computing hardware design.

3. Octal System

Octal is a base-8 number system using eight symbols: 0 through 7 to represent values. In computers, octal notation is frequently employed to denote file permissions or device addresses due to its compact representation of binary data (groups of three bits). Each digit's position represents a power of eight; specifically, the $i$-th digit corresponds to $(8)^{i-1}$.

For example, the value "123" in octal is calculated as:
$$1 \times 8^2 + 2 \times 8^1 + 3 \times 8^0 = 64 + 16 + 3 = 85_{10}$$

4. Hexadecimal System

Hexadecimal (base-16) utilizes sixteen symbols: digits 0–9 and letters A–F to represent values, where A=10, B=11, ..., F=15. It is commonly used in computing to express memory addresses, color codes, and other compact binary representations. Each digit's position represents a power of sixteen; specifically, the $i$-th digit corresponds to $(16)^{i-1}$.

For example, the value "1A3" (where A=10) is calculated as:
$$1 \times 16^2 + 10 \times 16^1 + 3 \times 16^0 = 256 + 160 + 3 = 419_{10}$$

The use of letters A–F allows for the concise representation of large values. Furthermore, hexadecimal can be easily converted to binary (each hex digit maps directly to four bits), which has led to its widespread adoption in computer science and engineering contexts.

Measurement Units

In the field of computer organization, units such as Bit, Byte, Kilobyte, etc., are standard metrics used to describe data size, transmission rates, storage capacity, and processing speed. Their specific definitions include:

  1. Bit (Binary Digit): The smallest unit of information in a digital system, representing either binary value 0 or 1. All data within computers is ultimately stored and transmitted as bits; for example, letters, numbers, images, or audio signals can all be represented by sequences of bits.
  2. Byte: A commonly used storage unit consisting of typically eight bits (8-bit). In most computing architectures, a single character (letter, symbol, or digit) occupies exactly one byte of memory space. Storage capacity and data transfer rates are generally calculated in bytes; for instance, hard drive capacities are measured in Bytes, while network speeds are often expressed as Bits per second (bps) or Bytes per second (B/s).
  3. Kilobyte (KB), Megabyte (MB), Gigabyte (GB), Terabyte (TB): Due to the vast quantities of data involved in modern computing, larger units are required for measurement. In binary-based systems used by computers:
    • $1 \text{ KB} = 1024 \text{ Bytes}$
    • $1 \text{ MB} = 1024 \text{ KB}$
    • $1 \text{ GB} = 1024 \text{ MB}$
    • $1 \text{ TB} = 1024 \text{ GB}$

In addition to the above storage units, other measurement units are frequently encountered:

  • Millisecond (ms): Used to denote processing speed or program response time; equal to one-thousandth of a second ($1/1000$ s).
  • Megahertz (MHz): Often used to describe CPU clock speeds; equal to one million cycles per second.
  • Gigahertz (GHz): Used for high-speed processor descriptions; equal to one billion cycles per second.
  • Bits per second (bps): Commonly used to measure network transmission rates, representing the number of bits transmitted per second.
  • Bytes per second (B/s or Baud in some contexts): Often used to describe storage device read/write speeds and data transfer throughput over networks; represents bytes transferred per second.

In computer science, these units are extensively utilized. By adopting standard metrics like Bits, Bytes, MHz, GHz, etc., it becomes significantly easier to quantify, compare, and optimize the performance and functionality of computing systems.