Well, you use them when you want to know the values of bits. Tons of systems encode information on as few bits as possible to save space. Compression algorithms map character strings and numeric values to packed bit streams. Transmission protocols store flags and sometimes node addresses as some number of bits that aren't byte multiples. It's ubiquitous in embedded systems.
If you're writing code in higher level languages like JS or Python then the need for bitwise operations do not present themselves very often. Two examples requiring the use of bitwise operations are in these videos by Danial Shiffman:
Shameless plug here, but I wrote an article not so long ago about the use cases of bitmasking. I used JavaScript for my examples if that helps you to figure out why you would need it. I also highly recommend reading through the comments and discussion of the article. People mentioned a lot of use cases for bitmasking in general there.
Can you give some examples when we need bitwise shifting? I’m writing JS and can’t figure out why would I need to use shift.
Well, you use them when you want to know the values of bits. Tons of systems encode information on as few bits as possible to save space. Compression algorithms map character strings and numeric values to packed bit streams. Transmission protocols store flags and sometimes node addresses as some number of bits that aren't byte multiples. It's ubiquitous in embedded systems.
If you're writing code in higher level languages like JS or Python then the need for bitwise operations do not present themselves very often. Two examples requiring the use of bitwise operations are in these videos by Danial Shiffman:
youtube.com/watch?v=MlRlgbrAVOs
youtube.com/watch?v=meGcdIoTYgw
Some uses I can think for the shifting operators are:
Daniel Shiffman goes into more detail in this other video of his:
youtube.com/watch?v=oCBlwsY8sR4
They're useful for hash functions, and bitwise XOR can be used instead of integer addition but it's probably not actually any faster.
Shameless plug here, but I wrote an article not so long ago about the use cases of bitmasking. I used JavaScript for my examples if that helps you to figure out why you would need it. I also highly recommend reading through the comments and discussion of the article. People mentioned a lot of use cases for bitmasking in general there.
Bitmasks: A very esoteric (and impractical) way of managing booleans
Some Dood
For example in audio processing, when manually extracting samples from byte arrays.