bitmap

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2019 License: MIT Imports: 1 Imported by: 3

README

bitmap

Go Report Card Build Status codecov GoDoc

bitmap implements bitmap manipulation functions for byte slices of arbitrary size.

Installation

go get github.com/anexia-it/bitmap

Contributing

Contributions are always welcome, in every possible way. We are always happy to receive bug reports and pull requests.

License

bitmap is free software, licensed under the MIT license.

Documentation

Overview

Package bitmap provides functions for working with bitmaps stored as byte slices of arbitrary size

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clear

func Clear(b []byte, bit uint)

Clear clears a bit inside a given byte slice

Example
package main

import (
	"fmt"

	"github.com/anexia-it/bitmap"
)

func main() {
	m := []byte{0x80 | 0x40, 0x00, 0x00, 0x01}
	bitmap.Clear(m, 31)
	fmt.Printf("%x\n", m)
}
Output:

40000001

func IsSet

func IsSet(b []byte, bit uint) bool

IsSet checks if a bit is set inside a given byte slice

Example
package main

import (
	"fmt"

	"github.com/anexia-it/bitmap"
)

func main() {
	m := []byte{0xf0, 0x0f}

	fmt.Printf("%t %t %t %t %t %t %t %t %t %t %t %t %t %t %t %t",
		bitmap.IsSet(m, 0),
		bitmap.IsSet(m, 1),
		bitmap.IsSet(m, 2),
		bitmap.IsSet(m, 3),
		bitmap.IsSet(m, 4),
		bitmap.IsSet(m, 5),
		bitmap.IsSet(m, 6),
		bitmap.IsSet(m, 7),

		bitmap.IsSet(m, 8),
		bitmap.IsSet(m, 9),
		bitmap.IsSet(m, 10),
		bitmap.IsSet(m, 11),
		bitmap.IsSet(m, 12),
		bitmap.IsSet(m, 13),
		bitmap.IsSet(m, 14),
		bitmap.IsSet(m, 15),
	)
}
Output:

true true true true false false false false false false false false true true true true

func Mask

func Mask(b []byte, mask []byte) (masked []byte, err error)

Mask applies the given mask to a given byte slice

Example
package main

import (
	"fmt"

	"github.com/anexia-it/bitmap"
)

func main() {
	m := []byte{0x75}
	mask := []byte{0x5b}

	masked, err := bitmap.Mask(m, mask)
	if err != nil {
		panic(err)
	}
	fmt.Printf("%x\n", masked)
}
Output:

51

func Set

func Set(b []byte, bit uint)

Set sets a bit inside a given byte slice

Example
package main

import (
	"fmt"

	"github.com/anexia-it/bitmap"
)

func main() {
	m := make([]byte, 4)
	bitmap.Set(m, 0)
	bitmap.Set(m, 31)

	fmt.Printf("%x\n", m)
}
Output:

80000001

Types

This section is empty.

Jump to

Keyboard shortcuts

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