github.com/danil/iso8583@v0.21.0/bitmap64/bitmap64.go (about)

     1  package bitmap64
     2  
     3  // Bitmap holds bits with indexes within range from 1 to 64
     4  type Bitmap [8]byte
     5  
     6  func New(p []byte) Bitmap {
     7  	var b Bitmap
     8  	copy(b[:], p[:8])
     9  	return b
    10  }
    11  
    12  // Get returns true or false for the indexes of the bits in range from 1 to 64
    13  func (b *Bitmap) Get(i int) bool {
    14  	if i < 1 || i > 64 {
    15  		panic("index out of range from 1 to 64")
    16  	}
    17  	i -= 1
    18  	return b[i/8]&(1<<uint(7-i%8)) != 0
    19  }
    20  
    21  // Set sets true value for the indexes of the bits in range from 1 to 64
    22  func (b *Bitmap) Set(i int) {
    23  	if i < 1 || i > 64 {
    24  		panic("index out of range from 1 to 64")
    25  	}
    26  	i -= 1
    27  	b[i/8] |= 1 << uint(7-i%8)
    28  }