bits.go 474 B

12345678910111213141516171819202122232425
  1. package util
  2. //IsBitSet bit is from 0 to 31
  3. func IsBitSet(attr int, bit uint) bool {
  4. return IsBitSet64(int64(attr), bit)
  5. }
  6. // IsBitSet64 bit is from 0 to 63
  7. func IsBitSet64(attr int64, bit uint) bool {
  8. if bit >= 64 {
  9. return false
  10. }
  11. return (attr & (1 << bit)) != 0
  12. }
  13. //SetBit64 set bit to 1
  14. func SetBit64(attr int64, bit uint) int64 {
  15. return attr | (1 << bit)
  16. }
  17. //UnSetBit64 set bit to 0
  18. func UnSetBit64(attr int64, bit uint) int64 {
  19. return attr & ^(1 << bit)
  20. }