Basic Maths
Working with exponents
Xa * Xb == X(a+b) –> 25 * 23 = 28
Xa / Xb == X(a-b) –> 25 / 23 = 22 –> 23 / 25 = 2-2 –> 1⁄22
(Xa)b == X(a*b) –> (25)3 = 215
(https://www.youtube.com/playlist?list=PL0G-Nd0V5ZMoqKRtXInzWnaeUlY66W35V)
Power of two
Can you tell, without looking at the table below, how much is 225?
We can easily get the order of magnitude of big powers of two using the initial powers and doing some extrapolation. Here is a table with the real numbers.
Kilo | Mega | Giga | Tera | |
---|---|---|---|---|
20 = 1 | 210 = 1.024 | 220 = 1.048.576 | 230 = 1.073.741.824 | 240 = 1.099.511.627.776 |
21 = 2 | 211 = 2.048 | 221 = 2.097.152 | 231 = 2.147.483.648 | |
22 = 4 | 212 = 4.096 | 222 = 4.194.304 | 232 = 4.294.967.296 | |
23 = 8 | 213 = 8.192 | 223 = 8.388.608 | 233 = 8.589.934.592 | |
24 = 16 | 214 = 16.384 | 224 = 16.777.216 | 234 = 17.179.869.184 | 264 = 18.446.744.073.709.551.616 |
25 = 32 | 215 = 32.768 | 225 = 33.554.432 | 235 = 34.359.738.368 | |
26 = 64 | 216 = 65.536 | 226 = 67.108.864 | 236 = 68.719.476.736 | |
27 = 128 | 217 = 131.072 | 227 = 134.217.728 | 237 = 137.438.953.472 | |
28 = 256 | 218 = 262.144 | 228 = 268.435.456 | 238 = 274.877.906.944 | |
29 = 512 | 219 = 524.288 | 229 = 536.870.912 | 239 = 549.755.813.888 |
In bold the “initial” numbers, which can be seen in the rest of columns. The “extrapolation” increases when going to the right, but the order of magnitude is correct: we can extrapolate that 225 will be 32.000.000. This is by taking 5 from the 25, which indicates the initial power 25 (32). Then we take 2 of the 25. Each unit is a factor of 1000, so 2 is 1.000.000 (or 2 groups of 3 zeros). This gives us an order of magnitude of 32.000.000.
These powers of two are just the mathematical calculations. In CS, they can represent, for instance, the number of bits needed to represent numbers: with 3 bits, we can represent 23 = 8 numbers. To be precise, from 0 to 7. They can also represent the number of XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Playing with 2…
When we add or subtract powers of 2, we multiply or divide by 2 each time.
Grouping things can lead sometimes to do fast (“wrong”) calculations. For instance, 32 bit
Taking into account that a byte are 8 bits (2)