Number & logic
The math every circuit is written in: how computers count in binary and hexadecimal, the algebra of true and false, and the truth tables that completely specify any logic function.
Binary numbersCounting with two symbolsA wire holds one of two values, so computers count in base 2. Place value, counting up, and the byte: the number system every later lesson is written in.HexadecimalBinary in a readable shorthandHex is base 16: one hex digit packs exactly four bits. It is how we write bytes and addresses without drowning in long strings of 0s and 1s.OctalThree bits to a digitOctal packs three bits into one base-8 digit (0 to 7), an older binary shorthand still seen in file permissions and some machine encodings.Number bases and base conversionTurning any number into any base by handConvert between decimal, binary, octal, and hexadecimal by hand: subtract powers or divide by 2, group bits by 3 or 4, handle fractions, and even solve for an unknown base.Bits, bytes, and KiB vs KBCounting storage, and the 1024 versus 1000 gapA byte is 8 bits, and storage prefixes come in a binary flavor (KiB = 1024) and a decimal flavor (KB = 1000), which is why a 500 GB drive shows less capacity in the operating system.Two's complementHow hardware stores negative numbersTwo's complement encodes a signed number by giving the top bit a negative weight, so one adder handles both addition and subtraction. To negate a value, invert every bit and add one.Sign extensionWidening a signed number without changing itSign extension copies a signed number's top bit into every new high bit when widening it, so a negative value stays the same negative value instead of turning into a large positive one.From counting in binary to addingThe carry rule you already knowBinary addition follows the same column-and-carry rule as decimal, and turning that paper procedure into gates is exactly what an adder does.Boolean algebraThe math of true and falseAND, OR, and NOT obey an algebra, with identities and De Morgan's laws that let you rewrite any logic expression. Reshaping expressions is exactly how you choose a circuit.De Morgan's lawsPushing a NOT through a gateThe inverse of an AND is an OR of the inverses, and the inverse of an OR is an AND of the inverses. These two laws are how you move a NOT across a gate and convert freely between AND, OR, NAND, and NOR forms.Boolean identities and dualityThe laws that simplify an expression by handThe identity, null, idempotent, complement, and absorption laws, plus the duality principle that swaps AND with OR and 0 with 1, let you shrink a Boolean expression algebraically before you ever draw a K-map.Truth tablesSpecifying logic, completelyA truth table lists the output for every possible input. It is the unambiguous specification of any logic function, the thing you verify against and the starting point for designing a gate.A bit is a number and a truth valueThe bridge from counting to logicThe same 0 and 1 that spell a number in binary also mean false and true, so arithmetic and logic run on the exact same wires.Gray codeCounting with one bit changing at a timeGray code reorders the binary count so that each step flips exactly one bit. That single-bit-change property avoids the transient wrong readings you get when several bits switch at once, which is why encoders and counters use it.Binary-coded decimal (BCD)Storing decimal digits one nibble eachBCD stores each decimal digit in its own 4-bit group using the 8421 weights, so 0 to 9 map to 0000 to 1001. It keeps numbers exactly decimal for money and displays, at the cost of six wasted codes and harder arithmetic.ASCII and character encodingHow text becomes numbersA computer only stores numbers, so text is stored by assigning every character a code. ASCII is the classic 7-bit table: 'A' is 65, '0' is 48, 'a' is 97, and the tidy gaps between those ranges make case conversion and digit reading a single subtraction.Error detection and correctionParity, Hamming distance, and ECCAdding redundant bits lets hardware catch and even repair bit flips: a parity bit detects any single error, and a Hamming code locates and corrects one. The cost is extra storage or bandwidth.Fixed-point fractionsPutting a binary point at a fixed columnFixed-point notation places an imaginary binary point at an agreed column so a whole-number circuit can represent fractions, the simpler cousin of floating point.Floating point (IEEE-754)Scientific notation in binaryFloating point stores a real number as a sign, a biased exponent, and a fractional mantissa, so a fixed number of bits can hold both huge and tiny values. IEEE-754 is the universal standard, with a hidden leading 1, reserved patterns for zero, infinity, and NaN, and round-to-nearest-even.