Have you ever had to use bit shifting in real projects?

后端 未结 30 3668
故里飘歌
故里飘歌 2020-12-02 05:35

Have you ever had to use bit shifting in real programming projects? Most (if not all) high level languages have shift operators in them, but when would you actually need to

相关标签:
30条回答
  • 2020-12-02 06:09

    I work for a computer peripheral manufacturer. I've encountered, and had to implement code that uses bit shifts, pretty much every day.

    0 讨论(0)
  • 2020-12-02 06:11

    I had to write a program to parse the .ifo files on DVD discs. These are the fileds that explain how many titles, chapters, menus, etc. are on the disc. They are made up of packed bits of all sizes and alignments. I suspect many binary formats require similar bit shifting.

    0 讨论(0)
  • 2020-12-02 06:12

    Yes, I've used them a lot of times. Bit twiddling is important on embedded hardware where bit-masks are very common. It's also important in games programming, when you need every last bit of performance.

    Edit: Also, I use them a lot for manipulating bitmaps, for example changing the colour depth, or converting RGB <-> BGR.

    0 讨论(0)
  • 2020-12-02 06:14

    I've used them a few times, but pretty much always for parsing a binary file format.

    0 讨论(0)
  • 2020-12-02 06:14

    For example, in cryptographic methods implementation on languages such as C, C++. Binary files, compression algorithms and logical lists operations - bitwise operation is always good =)

    0 讨论(0)
  • 2020-12-02 06:14

    Yes, when performing binary communication between Java and C# applications, one is big-endian byte ordering and the other is little-endian (not necessarily on this order). I created an InputStream class that could read numbers with a different byte order, and it used byte-shifting in order to work.

    Sometimes also when you want to put 4 shorts in the 4 bytes of a long, it would be case the of using byte shifting. I think I did that many years ago...

    0 讨论(0)
提交回复
热议问题