I am new to bitwise operators.
I understand how the logic functions work to get the final result. For example, when you bitwise AND
two numbers, the final result is going to be the AND
of those two numbers (1 & 0 = 0
; 1 & 1 = 1
; 0 & 0 = 0
). Same with OR
, XOR
, and NOT
.
What I don't understand is their application. I tried looking everywhere and most of them just explain how bitwise operations work. Of all the bitwise operators I only understand the application of shift operators (multiplication and division). I also came across masking. I understand that masking is done using bitwise AND
but what exactly is its purpose and where and how can I use it?
Can you elaborate on how I can use masking? Are there similar uses for OR
and XOR
?