bitmask

package
v0.18.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 21, 2024 License: MIT Imports: 1 Imported by: 4

Documentation

Overview

bitmasks are a way to store multiple boolean values in a single integer

Example
package main

import (
	"fmt"

	"simonwaldherr.de/go/golibs/bitmask"
)

func main() {
	i := bitmask.New(0b11111111)

	i.Set(0, false)
	fmt.Println(i)

	i.Set(3, false)
	fmt.Println(i)

	i.Set(0, true)
	fmt.Println(i)

	fmt.Println("2:", i.Get(2))

	fmt.Printf("[]byte: %b\n", i.Byte())

}
Output:

11111110
11110110
11110111
2: true
[]byte: [11110111]

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bitmask

type Bitmask struct {
	// contains filtered or unexported fields
}

func New

func New(init int) *Bitmask

New creates a new Bitmask

func (*Bitmask) Byte

func (b *Bitmask) Byte() []byte

Byte returns the byte representation of the bitmask

func (*Bitmask) Get

func (b *Bitmask) Get(pos int) bool

Get returns the value of the bit at position pos

func (*Bitmask) Int

func (b *Bitmask) Int() int

Int returns the integer value of the bitmask

func (*Bitmask) Set

func (b *Bitmask) Set(pos int, val bool) int

Set sets the bit at position pos to val

func (*Bitmask) String

func (b *Bitmask) String() string

String returns the string representation of the bitmask

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL