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

后端 未结 30 3763
故里飘歌
故里飘歌 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: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...

提交回复
热议问题