|
| 1 | +--- |
| 2 | +title: Number Systems & Memory Organization |
| 3 | +date: |
| 4 | +--- |
| 5 | + |
| 6 | +## Number system fundamentals |
| 7 | + |
| 8 | +Digital systems use several bases to represent information: |
| 9 | + |
| 10 | +- **Decimal (base 10):** digits $0$–$9$, human-friendly. |
| 11 | +- **Binary (base 2):** digits $0$–$1$, directly matches on/off electrical signals in hardware. |
| 12 | +- **Hexadecimal (base 16):** digits $0$–$9$ and $A$–$F$ (representing $10$–$15$), a compact way to write binary. |
| 13 | +- Other bases (e.g., ternary base $3$, quaternary base $4$) are conceptually similar. |
| 14 | + |
| 15 | +All positional number systems use powers of the base: |
| 16 | + |
| 17 | +- Rightmost digit is position $0$, next is position $1$, etc. |
| 18 | +- Value $=$ sum over $\text{digit} \times \text{base}^{\text{position}}$. |
| 19 | + |
| 20 | +Example (binary $1011_2$): |
| 21 | + |
| 22 | +$$ |
| 23 | +1011_2 = 1 \cdot 2^3 + 0 \cdot 2^2 + 1 \cdot 2^1 + 1 \cdot 2^0 |
| 24 | += 8 + 0 + 2 + 1 = 11_{10}. |
| 25 | +$$ |
| 26 | + |
| 27 | +## Base conversions |
| 28 | + |
| 29 | +### To decimal (positional expansion) |
| 30 | + |
| 31 | +- **Binary -> decimal:** multiply each bit by the corresponding power of $2$ and add. |
| 32 | +- **Hex -> decimal:** multiply each hex digit by the corresponding power of $16$ and add. |
| 33 | + |
| 34 | +Example: |
| 35 | + |
| 36 | +$$ |
| 37 | +(10110)_2 = 1 \cdot 2^4 + 0 \cdot 2^3 + 1 \cdot 2^2 + 1 \cdot 2^1 + 0 \cdot 2^0 = 22_{10}. |
| 38 | +$$ |
| 39 | + |
| 40 | +$$ |
| 41 | +(\text{AE3})_{16} = 10 \cdot 16^2 + 14 \cdot 16^1 + 3 \cdot 16^0 = 2787_{10}. |
| 42 | +$$ |
| 43 | + |
| 44 | +### From decimal (repeated division) |
| 45 | + |
| 46 | +Use repeated division by the target base, tracking remainders: |
| 47 | + |
| 48 | +- **Decimal -> binary:** divide by $2$ until the quotient is $0$, read remainders bottom-to-top. |
| 49 | +- **Decimal -> hex:** same idea but divide by $16$. |
| 50 | + |
| 51 | +Example: |
| 52 | + |
| 53 | +- $20_{10} \to$ binary: remainders give $(10100)_2$. |
| 54 | +- $20_{10} \to$ hex: remainders give $(14)_{16}$. |
| 55 | + |
| 56 | +### Direct binary–hex mapping |
| 57 | + |
| 58 | +Because $16 = 2^4$, $4$ binary bits correspond to $1$ hex digit: |
| 59 | + |
| 60 | +- **Binary -> hex:** group bits into $4$-bit chunks from the right, pad with leading zeros if needed, convert each chunk to hex. |
| 61 | +- **Hex -> binary:** replace each hex digit with its $4$-bit binary equivalent. |
| 62 | + |
| 63 | +Example: |
| 64 | + |
| 65 | +- $(110100)_2 \to 0011\,0100 \to (34)_{16}$. |
| 66 | +- $(\text{B2F})_{16} \to 1011\,0010\,1111_2$. |
| 67 | + |
| 68 | +A small table (for $0$–$15$) links decimal, hex, and $4$-bit binary. |
| 69 | + |
| 70 | +## Data representation |
| 71 | + |
| 72 | +### Bits, bytes, and larger units |
| 73 | + |
| 74 | +- $1$ **bit** $=$ $1$ binary digit ($0$ or $1$). |
| 75 | +- $1$ **byte** $=$ $8$ bits. |
| 76 | +- $1$ **KB** $=$ $2^{10}$ bytes $= 1024$ bytes. |
| 77 | +- $1$ **MB** $=$ $2^{10}$ KB. |
| 78 | +- $1$ **GB** $=$ $2^{10}$ MB. |
| 79 | +- $1$ **TB** $=$ $2^{10}$ GB. |
| 80 | + |
| 81 | +An $n$-bit quantity can represent $2^n$ distinct values: |
| 82 | + |
| 83 | +- $1$ bit -> $2$ values. |
| 84 | +- $8$ bits ($1$ byte) -> $2^8 = 256$ values. |
| 85 | + |
| 86 | +### Text encoding |
| 87 | + |
| 88 | +- **ASCII:** uses $1$ byte ($8$ bits) per character; can encode up to $256$ characters (e.g., `'A' = 65_{10}$). |
| 89 | +- **Unicode:** uses $16$ bits or more; supports many languages and symbols ($2^{16}$ or more code points). |
| 90 | + |
| 91 | +### Numbers |
| 92 | + |
| 93 | +- **Integers:** stored as binary whole numbers (with specific schemes for signed vs unsigned). |
| 94 | +- **Floating-point:** used for real numbers; stored using standardized formats (e.g., IEEE-754) with finite precision, so not all real values can be represented exactly. |
| 95 | + |
| 96 | +## Memory organization |
| 97 | + |
| 98 | +### Addresses vs contents |
| 99 | + |
| 100 | +Memory is a collection of storage cells: |
| 101 | + |
| 102 | +- **Memory address:** where data is stored (an index/location). |
| 103 | +- **Memory content:** the bits actually stored at that address. |
| 104 | + |
| 105 | +For an $n$-bit memory **location**: |
| 106 | + |
| 107 | +- It can store one of $2^n$ different values (because the content has $n$ bits). |
| 108 | + |
| 109 | +For an $n$-bit **address**: |
| 110 | + |
| 111 | +- It can point to $2^n$ distinct locations. |
| 112 | + |
| 113 | +Example: |
| 114 | + |
| 115 | +- $32$-bit data cell -> $2^{32}$ possible contents. |
| 116 | +- $16$-bit address -> $2^{16} = 64\text{K}$ addressable locations. |
| 117 | + |
| 118 | +### Size and powers of two |
| 119 | + |
| 120 | +Useful powers of two: |
| 121 | + |
| 122 | +- $2^{10} = 1024 \approx 1\text{K}$ |
| 123 | +- $2^{20} \approx 1\text{M}$ |
| 124 | +- $2^{30} \approx 1\text{G}$ |
| 125 | +- $2^{40} \approx 1\text{T}$ |
| 126 | + |
| 127 | +Key rules: |
| 128 | + |
| 129 | +$$ |
| 130 | +2^n \cdot 2^m = 2^{n+m}, \quad \log_2(nm) = \log_2(n) + \log_2(m). |
| 131 | +$$ |
| 132 | + |
| 133 | +Examples: |
| 134 | + |
| 135 | +- $2^{16} = 2^{10} \cdot 2^6 = 1\text{K} \cdot 64 = 64\text{K}$. |
| 136 | +- If a system has a $24$-bit address bus, it can address $2^{24}$ bytes $= 16\text{MB}$. |
| 137 | + |
| 138 | +### Basic computer architecture |
| 139 | + |
| 140 | +A simplified view: |
| 141 | + |
| 142 | +- **CPU** connects to **RAM** using three buses: |
| 143 | + - **Address bus:** selects which memory location to access. |
| 144 | + - **Data bus:** carries data between CPU and memory. |
| 145 | + - **Control bus:** carries control signals (read/write, etc.). |
| 146 | + |
| 147 | +The width of the address bus determines the maximum directly addressable memory. |
| 148 | + |
| 149 | +## Practice and examples |
| 150 | + |
| 151 | +The note includes worked examples on: |
| 152 | + |
| 153 | +1. **Base conversions:** |
| 154 | + - Binary <-> decimal. |
| 155 | + - Hex <-> decimal. |
| 156 | + - Decimal <-> binary via repeated division. |
| 157 | + - Hex <-> binary via $4$-bit grouping. |
| 158 | + |
| 159 | +2. **Memory calculations:** |
| 160 | + - Bits needed to address a given memory size (e.g., $8\text{MB}$ requires $23$ address bits). |
| 161 | + - Maximum memory size from a given address width (e.g., $24$-bit address bus -> $16\text{MB}$). |
| 162 | + |
| 163 | +3. **Data values in $n$-bit locations:** |
| 164 | + - Counting the number of distinct values (e.g., a $12$-bit cell stores $2^{12} = 4096$ values). |
| 165 | + |
| 166 | +## Quick reference |
| 167 | + |
| 168 | +Common facts: |
| 169 | + |
| 170 | +- $1$ byte $= 8$ bits. |
| 171 | +- $1$ KB $= 1024$ bytes. |
| 172 | +- $1$ MB $= 1024$ KB. |
| 173 | +- $1$ GB $= 1024$ MB. |
| 174 | +- $1$ TB $= 1024$ GB. |
| 175 | + |
| 176 | +Hex <-> $4$-bit binary shortcuts: |
| 177 | + |
| 178 | +- $A = 1010$, $B = 1011$, $C = 1100$, $D = 1101$, $E = 1110$, $F = 1111$. |
| 179 | + |
| 180 | +Frequent mistakes to avoid: |
| 181 | + |
| 182 | +1. Confusing memory **addresses** with memory **contents**. |
| 183 | +2. Forgetting to pad binary with leading zeros when grouping for hex. |
| 184 | +3. Using $1000$ instead of $1024$ for KB/MB/GB in CS contexts. |
| 185 | +4. Reading division remainders in the wrong order in base conversion. |
| 186 | +5. Misplacing powers of the base in positional notation. |
0 commit comments