June 2017
Beginner
502 pages
11h 26m
English
This is the bitwise AND operator; it is similar to a logical AND but works on the bit mask on the binary representation of the integer. The binary bits are read from left to right and compared between the two numbers: if, in the same position of each number, we find a 1, the result will be 1, otherwise it will be 0:
zarrelli:~$ x=50 ; y=20; echo $((x&y))16
How did we come to such a value? Let's create a matrix with the binary values of 50 and 20:
|
128 |
64 |
32 |
16 |
8 |
4 |
2 |
1 |
|
|
50 |
0 |
0 |
1 |
1 |
0 |
0 |
1 |
0 |
|
20 |
0 |
0 |
0 |
1 |
0 |
1 |
0 |
0 |
|
& |
0 |
0 |
0 |
1 |
0 |
0 |
0 |
0 |
The result is the binary 00010000, which in decimal is 16.
Read now
Unlock full access