Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

What is the purpose of bitwise shifting?

I never really used bitwise shifting, and I'm kind of taking interest in it now. I get the basic idea; but is all bitwise shifting used for is an alternative to arithmetic? Or is there something deeper then CPU efficient math that I'm missing?

1 Answer

Relevance
  • 1 decade ago
    Favorite Answer

    If you pack an integer by flipping the individual bits, you can then check the new value of the integer (which would be 31 bits long). That way, you can have code that checks a poker hand using a number like 12 decimal to know that particular hand was 2-of-a-kind (binary 0000011000 ). To determine the same thing otherwise would take a big if() else if() else() tree.

    Bit flipping becomes exceptionally useful in 3D graphics, that would be your concept of the arithmetic.

Still have questions? Get your answers by asking now.