Comprehensive Notes on Binary Representation, Boolean Logic, and Computer Architecture
Character Encoding and Text Representation
General Concept of Binary Representation: Everything in a computer—including video games, music, and images—must be represented at the most base level as ones and zeros. This process of representing worldly experience in binary is known as binary representation.
Inventory of Characters: To represent text, the computer must map characters to numbers. Characters include: - Lowercase letters: 26 characters. - Uppercase letters: 26 characters. - Space bar: At least one character. - Punctuation: Comma, decimal, periods, semicolons, colons, parentheses, brackets, etc. - Numbers: Even though they are numbers, when printed on a screen, they are symbols (characters) rather than mathematical values stored in the computer's "brain."
Determining Bit Count: The number of things that can be stored is determined by the formula , where is the number of bits. - 1 bit = = 2 things ( and ). - 2 bits = = 4 things (, , , ). - 3 bits = = 8 things ( to ).
ASCII (American Standard Code for Information Interchange): - Developed in the 1950s and 60s. - Uses 7 bits to represent 128 characters ( to ). - Maps English characters and punctuation to numbers. Examples: - Space = - Number "1" = - Number "2" = - Capital Letters = Start at - Lowercase Letters = Start at - Special Control Characters: The first ~30 characters include things like the "Bell" (which used to ring a physical bell, now a beep) and typewriter-based commands.
Typewriter Influence (Carriage Return and Line Feed): - Modern computer "Enter" keys often still use the arrow symbol representing typewriter mechanics. - Carriage Return: Moving the carriage back to the start of the line. - Line Feed: Moving the paper down to the next line. - In code, the "Enter" action is actually two distinct symbols: carriage return and line feed.
Extended ASCII: By adding just one bit to make it an 8-bit system ( characters), the chart doubled in size. This allowed for international symbols (Yen marker, Pound), Greek letters for math, and "box-drawing" characters used to create windows in text-based interfaces.
Unicode: - Provides a much larger room for characters (currently almost 300,000 characters, with room to grow). - Includes emojis, which are managed by a consortium from Japan. - Emoji Application Process: Anyone can apply for a new emoji. Subcommittees review applications and then a larger committee votes. They approve the name and description, but individual companies (Apple, Google, etc.) design their own visual versions. - Example: A group of adults voted multiple times to approve the "smiling pile of poo" as a required part of text-based communication.
Representing Negative Numbers and Two's Complement
Overflow Definition: Overflow occurs when a mathematical result exceeds the physical number of columns (bits) available in a system. In computers, the extra digit is simply "thrown away."
Hundreds Complement (Decimal Analogy): - In a hypothetical 2-digit decimal system ( to ), adding something to that results in (due to overflow) identifies the negative version of that number. - If , and we throw away the (the overflow), the result is . Therefore, in this system, acts as .
One's Complement: To find the negative of a binary number like 5 (), you "flip the bits" or invert them, turning every to a and every to a .
Two's Complement (Standard System): This is the primary way computers represent negative numbers because it allows the hardware to add and subtract using the same addition circuitry. - Step 1: Write the positive version of the number in binary. - Step 2: Flip the bits (One's Complement). - Step 3: Add to the result. - Adding a negative number in two's complement to its positive counterpart will result in zero (plus an overflow bit that the computer ignores).
Real Numbers and Floating Point Notation
IEEE Floating Point Notation: Developed by the Institute of Electrical and Electronics Engineers (IEEE) to represent real (decimal/fractional) numbers. It is based on scientific notation: .
Components of a Float: - Sign: One bit representing positive or negative. - Mantissa: Also called the fractional part. - Exponent: The power the base is raised to.
Precision and Limits: - Float: 32-bit representation. - Double: Twice as large (64-bit), offering more accuracy. - Place Values in Binary Fractions: - - - -
Floating Point Error: Computers cannot perfectly represent every possible real number. Because numbers are stored as a finite collection of fractions, some values are impossible to reach exactly. This creates local imperfections or "errors" that programmers must manage, especially in sensitive areas like banking (where money is usually stored as two whole numbers: dollars and cents).
Boolean Logic and Logic Gates
Boolean Algebra: Named after George Boole. It operates on bits (True/False, On/Off, 1/0). Computer circuits are built out of these logical relationships.
Logic Gates with Two Inputs (AND, OR): - AND Gate: The output is only when BOTH inputs are . (Example: "If you get an A in math AND an A in English, you get ice cream.") - OR Gate: The output is if EITHER input (or both) is . It is only when both inputs are .
The NOT Gate: A single-input gate that "inverts" the value. If input is , output is . If input is , output is .
Derived Gates: - NAND (Not AND): The opposite of an AND gate (). - NOR (Not OR): The opposite of an OR gate (). - XOR (Exclusive OR): The output is only true () if exactly one of the inputs is on. If both are off or both are on, the output is .
Practical Computer Architecture: Adders and Latches
The Adder: A circuit that adds binary numbers together using logic gates. - Half Adder: Consists of an XOR gate (to find the sum ) and an AND gate (to find the carry ). - Truth Table for Adder: - (Sum), (Carry) - (Sum), (Carry) - (Sum), (Carry) [Resulting in binary , which is ] - Full Adder: A series of connected adders (e.g., 64 of them for a 64-bit machine) that can process carries from previous columns.
Memory and Latches: Circuits used to store bits. - SR Latch: Can be "Set" (made ) or "Reset" (made ). - NAND Flash: Most common flash memory is built entirely out of millions of NAND gates.
Physical Nature of Computing: These are not mechanical; they are chemical and electrical processes. Transistors on silicon wafers allow electricity to flow through these circuits without moving parts.
ALU (Arithmetic Logic Unit): The part of the CPU where these mathematical and logical calculations occur.
FPGA (Field Programmable Gate Array): A specialized chip containing a sea of gates that remain undefined until a programmer writes code to configure them into a specific circuit.