美文网首页
Bit Manipulation Summary

Bit Manipulation Summary

作者: stepsma | 来源:发表于2019-03-19 00:18 被阅读0次

来总结一下Bit Manipulation的一些常见操作:

  1. 将第n位bit 设为1:
  x |= (1 << n)
  1. 将第n位bit 设为0:
  x &= ~(1 << n)
  1. 将第n位bit toggle:
  x ^= (1 << n)
  1. check n位bit非0
  !(x & (1 << n))

相关文章

网友评论

      本文标题:Bit Manipulation Summary

      本文链接:https://www.haomeiwen.com/subject/qcqwmqtx.html