They do different things
What do you mean by binary operators? And, or, xor?
I know binary operations but not able to understand bit shift operator.
It shifts bits 🤷🏼♂️
00000001 << 2 = 00000100
For instance
what is the use of this shifting ?
Shifting bits
You can store 8 states in an 8 bit int
What I mean by this is that let's say you have 8 bool values, you don't need to keep track of 8 variables. Especially if you need to communicate these variables to other clients via sockets. Instead you shift and combine them using bitwise operators
This is not the only use of bit shifting tho
I could imagine, though I'm not familiar with other examples
You can use it to multiply or divide by powers of 2 and you can use it with bitmasks to access certain data
Обсуждают сегодня