Page 159 - JavaScript
P. 159
console.log(13 * (2 ** 6)) //13 * 64 = 832
console.log(13 << 6) // 832
Similarly, to do (floored) integer division by 2 ** n, we can right shift by n bits. Example:
console.log(1000 / (2 ** 4)) //1000 / 16 = 62.5
console.log(1000 >> 4) // 62
It even works with negative numbers:
console.log(-80 / (2 ** 3)) //-80 / 8 = -10
console.log(-80 >> 3) // -10
In reality, speed of arithmetic is unlikely to significantly impact how long your code takes to run,
unless you are doing on the order of 100s of millions of computations. But C programmers love
this sort of thing!
Read Bitwise Operators - Real World Examples (snippets) online:
https://riptutorial.com/javascript/topic/9802/bitwise-operators---real-world-examples--snippets-
https://riptutorial.com/ 116

