BINARY • HEXADECIMAL • LOGIC
█ PLAYER 1 START █
binary is the language of computers. every piece of data, from your favorite game to this webpage, is ultimately represented as a sequence of 1s and 0s.
computers use binary because transistors (the building blocks of processors) have two states: ON (1) and OFF (0). it's like a light switch - either on or off, true or false, 1 or 0.
just like decimal uses powers of 10, binary uses powers of 2:
PRO TIP: only add the place values where there's a 1. ignore positions with 0.
to convert from decimal to binary, repeatedly divide by 2 and track the remainders:
unsigned binary numbers represent only positive values. the range for n bits is 0 to 2ⁿ - 1.
with 6 bits, you can represent: 0 to 63 (2⁶ - 1 = 64 - 1 = 63)
binary addition works just like decimal, but with carries at 2 instead of 10:
OVERFLOW DETECTION: overflow occurs when the result exceeds the maximum value that can be stored. for 6-bit unsigned, any result > 63 causes overflow. look for a carry out of the leftmost bit.
signed binary uses two's complement representation to handle both positive and negative numbers. the leftmost bit is the sign bit: 0 = positive, 1 = negative.
-32 to +31 (from -2⁵ to 2⁵ - 1)
positive: 000000 to 011111 (0 to 31)
negative: 100000 to 111111 (-32 to -1)
to represent a negative number:
SIGNED OVERFLOW: overflow in signed arithmetic occurs when:
• adding two positive numbers gives a negative result
• adding two negative numbers gives a positive result
• different signs CANNOT cause overflow
hexadecimal (base 16) is a compact way to represent binary. each hex digit represents exactly 4 binary bits.
WHY USE HEX? hex is much more compact than binary. the 16-bit binary number 1111111111111111 is just FFFF in hex!
truth tables enumerate all possible input combinations and their corresponding outputs. they're fundamental to understanding digital circuits and logic design.
• n inputs produce 2ⁿ rows
• every row must have a defined output (0 or 1)
• systematically list all binary combinations
• outputs determined by logical conditions
specification: four inputs (a,b,c,d). first two (a,b) represent a number 1-3. second two (c,d) represent another number 1-3. output y=1 if first > second OR second = first + 2.
| a | b | c | d | first | second | condition | y |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | - | - | invalid | 0 |
| 0 | 0 | 0 | 1 | - | 1 | invalid | 0 |
| 0 | 0 | 1 | 0 | - | 2 | invalid | 0 |
| 0 | 0 | 1 | 1 | - | 3 | invalid | 0 |
| 0 | 1 | 0 | 0 | 1 | - | invalid | 0 |
| 0 | 1 | 0 | 1 | 1 | 1 | 1 = 1 | 0 |
| 0 | 1 | 1 | 0 | 1 | 2 | 1 < 2 | 0 |
| 0 | 1 | 1 | 1 | 1 | 3 | 3 = 1+2 | 1 |
| 1 | 0 | 0 | 0 | 2 | - | invalid | 0 |
| 1 | 0 | 0 | 1 | 2 | 1 | 2 > 1 | 1 |
| 1 | 0 | 1 | 0 | 2 | 2 | 2 = 2 | 0 |
| 1 | 0 | 1 | 1 | 2 | 3 | 2 < 3 | 0 |
| 1 | 1 | 0 | 0 | 3 | - | invalid | 0 |
| 1 | 1 | 0 | 1 | 3 | 1 | 3 > 1 | 1 |
| 1 | 1 | 1 | 0 | 3 | 2 | 3 > 2 | 1 |
| 1 | 1 | 1 | 1 | 3 | 3 | 3 = 3 | 0 |
specification: four inputs (a,b,c,d). first two represent 0-2, second two represent 0-2 (3 not used). output y=1 if numbers don't differ by more than 1.
| a | b | c | d | first | second | |diff| | y |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
| 0 | 0 | 0 | 1 | 0 | 1 | 1 | 1 |
| 0 | 0 | 1 | 0 | 0 | 2 | 2 | 0 |
| 0 | 0 | 1 | 1 | 0 | - | - | 0 |
| 0 | 1 | 0 | 0 | 1 | 0 | 1 | 1 |
| 0 | 1 | 0 | 1 | 1 | 1 | 0 | 1 |
| 0 | 1 | 1 | 0 | 1 | 2 | 1 | 1 |
| 0 | 1 | 1 | 1 | 1 | - | - | 0 |
| 1 | 0 | 0 | 0 | 2 | 0 | 2 | 0 |
| 1 | 0 | 0 | 1 | 2 | 1 | 1 | 1 |
| 1 | 0 | 1 | 0 | 2 | 2 | 0 | 1 |
| 1 | 0 | 1 | 1 | 2 | - | - | 0 |
| 1 | 1 | 0 | 0 | - | 0 | - | 0 |
| 1 | 1 | 0 | 1 | - | 1 | - | 0 |
| 1 | 1 | 1 | 0 | - | 2 | - | 0 |
| 1 | 1 | 1 | 1 | - | - | - | 0 |
TRUTH TABLE STRATEGY:
1. understand the input encoding
2. list all 2ⁿ combinations systematically
3. decode inputs to actual values
4. apply logical conditions
5. assign output based on conditions
6. mark invalid/unused combinations