Dividing by power of 2 using bit shifting

后端 未结 4 891
失恋的感觉
失恋的感觉 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:31

    Negative numbers work out to be one off in the binary representation due to their two's complement representation. Perhaps reading about two's complement will help.

提交回复
热议问题