loading...

re: Bitwise Operations in C/C++ VIEW POST

TOP OF THREAD FULL DISCUSSION
re: 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.
 

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:

  1. To create a bitmask
  2. One of the operations to convert the endianness of some multi-bit value
  3. If you shift a value by 2 then it's a shortcut for multiplication or division by two depending on shift operator used.

Daniel Shiffman goes into more detail in this other video of his:

youtube.com/watch?v=oCBlwsY8sR4

code of conduct - report abuse