They tell me "to encrypt an int change bit # 3 from 0 to 1 using bitwise", I need an explanation from this operator, I have no idea of its syntax or how to use it ..
They tell me "to encrypt an int change bit # 3 from 0 to 1 using bitwise", I need an explanation from this operator, I have no idea of its syntax or how to use it ..
Good morning,
The Bitwise
operators work at the bit level, allowing to change the specific bit values:
Example:
We are going to use, for example, the Bitwise operator ~
:
If we have a = ~2
- > a = -3
Explanation:
The operator ~
reverses all the bits of the number you have put behind, in this case the 2 - > 0000 0010
If we invert all the bits of 2 we have the following: 1111 1101
that is -3
I hope it helps you.