June 2017
Beginner
502 pages
11h 26m
English
The bitwise left shift operators simply multiplies by 2 a value for each shift position; the following example will make everything more clear:
zarrelli:~$ x=10 ; echo $((x<<1))20zarrelli:~$ x=10 ; echo $((x<<2))40zarrelli:~$ x=10 ; echo $((x<<3))80zarrelli:~$ x=10 ; echo $((x<<4))160
What happened? As we said before, the bitwise operators work on a bit mask, so let's start converting the integer 10 to its binary representation in 16-bit and using a power of 2 table to check the values.
In this case, a simple method to represent a decimal in a binary form is to use the power of two notations, starting with dividing our integer in a sum of power of two numbers. In our example, the highest power of two that fits into 10 is ...
Read now
Unlock full access