https://github.com/josestg/bitfield
The BitField package provides the primitives to work with bitfields in Go. This package is very simple and can be used to implement more complex data structures such as bitsets, bloom filters, etc.
https://github.com/josestg/bitfield
Last synced: about 1 month ago
JSON representation
The BitField package provides the primitives to work with bitfields in Go. This package is very simple and can be used to implement more complex data structures such as bitsets, bloom filters, etc.
- Host: GitHub
- URL: https://github.com/josestg/bitfield
- Owner: josestg
- License: mit
- Created: 2023-09-09T14:55:48.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-09-09T16:17:20.000Z (over 1 year ago)
- Last Synced: 2025-01-31T06:47:21.169Z (3 months ago)
- Language: Go
- Homepage:
- Size: 3.91 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BitField
The `BitField` package provides the primitives to work with bitfields in Go. This package is very simple and
can be used to implement more complex data structures such as bitsets, bloom filters, etc.The `BitField` is implemented using `uint64` type, so it can hold up to 64 bits for one bitfield. To work with
bitfields larger than 64 bits, you can combine multiple `BitField` as an array to build bigger bitfields.## Installation
```bash
go get github.com/josestg/bitfield
```## Usage
```go
package mainimport (
"fmt"
"github.com/josestg/bitfield"
)func main() {
var f bitfield.BitField
f = f.SetBit(0).SetBit(1).SetBit(3).SetBit(4)
fmt.Printf("%08b\n", f) // 00011011
fmt.Println(f.IsSet(0)) // true
fmt.Println(f.IsSet(2)) // false
fmt.Println(f.IsSet(3)) // true
fmt.Println(f.Cardinal()) // 4g := f.DelBit(3)
fmt.Println(g.IsSet(3)) // false
}
```