go-bit

module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2019 License: Apache-2.0

README

go-bit

Build Status Go Report Card GoDoc

A library to read/write bits from a byte slice.

Installation

$ go get github.com/nokute78/go-bit/pkg/bit

Usage

package main

import (
	"fmt"
	"github.com/nokute78/go-bit/pkg/bit"
)

func main() {
	b := []byte{0x78} /* 0111_1000 in bit */

	/* try to get 4bits(1111b) from 0111_1000 */
	off := bit.Offset{Byte: 0, Bit: 3}

	ret, err := bit.GetBits(b, off, 4)
	if err != nil {
		fmt.Printf("error:%s\n", err)
	}

	fmt.Printf("0x%x\n", ret) /* Print 0x0f = 1111b */
}

Tool

License

Apache License v2.0

Directories

Path Synopsis
cmd
pkg
bit
Package bit provides functions for bit.
Package bit provides functions for bit.

Jump to

Keyboard shortcuts

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