How can I tell if a number is a multiple of four using only the logic operator AND?

后端 未结 4 1978
终归单人心
终归单人心 2020-12-30 12:41

I\'m messing with assembly language programming and I\'m curious how I could tell if a number is a multiple of 4 using the logic operator AND?

I know how to do it us

4条回答
  •  天涯浪人
    2020-12-30 13:22

    A number is a multiple of 4 if its lower 2 bits are 0, so you can simply shift the number right twice and check shifted bits for 0.

提交回复
热议问题