github.com/cilium/cilium@v1.16.2/pkg/hubble/math/bits.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Hubble
     3  
     4  package math
     5  
     6  // MSB returns the position of most significant bit for the given uint64
     7  func MSB(x uint64) uint8 {
     8  	var i uint8
     9  	for ; (x >> i) != 0; i++ {
    10  	}
    11  	return i
    12  }
    13  
    14  // GetMask returns a bit mask filled with ones of length 'x'.
    15  // e.g.:
    16  // GetMask(3) => 0b00000111
    17  // GetMask(4) => 0b00001111
    18  // GetMask(5) => 0x00011111
    19  func GetMask(x uint8) uint64 {
    20  	return ^uint64(0) >> (64 - x)
    21  }