June 2017
Beginner
502 pages
11h 26m
English
The bitwise NOT is a unary operator, and this means it is used with just one operator, flipping the bit used to represent the integer in binary notation:
zarrelli:~$ x=50 ; echo $((~x))-51
Have a look at the following table:
|
128 |
64 |
32 |
16 |
8 |
4 |
2 |
1 |
|
|
50 |
0 |
0 |
1 |
1 |
0 |
0 |
1 |
0 |
|
~ |
1 |
1 |
0 |
0 |
1 |
1 |
0 |
1 |
|
-128 |
64 |
8 |
4 |
1 |
We have to keep in mind that the most significant bit on the left for a signed integer (and this is a signed integer, even though we do not write +50 because Bash represents integer with a sign long at 64-bit) holds the sign value. So, flipping the first significant bit actually inverted the value. As the rule of thumb, the bitwise NOT leads to the same ...
Read now
Unlock full access