Dividing by power of 2 using bit shifting

后端 未结 4 893
失恋的感觉
失恋的感觉 2020-12-28 23:05

I\'ve got the following task:

Compute x/(2^n), for 0 <= n <= 30 using bit shifting.

Requirement: Round toward zero

4条回答
  •  遥遥无期
    2020-12-28 23:20

    Pay close attention to the rounding behavior.

    • / (integer divide) always rounds toward zero.
    • What does bit shifting do?
    • How can you compensate for this difference?

提交回复
热议问题