biu

package module
v0.0.0-...-0376ce6 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2017 License: MIT Imports: 3 Imported by: 18

README

Biu

biu is a golang binary util. you can convert bytes to different string format(binary,hex,octal. support binary format only right now), even can convert your data(basic data type) to different string format directly. And you can also convert a string in binary,hex or octal format to a data with data type whatever you wanted.

Features

  • high performance
  • easy to use
  • rich data type support

Quick Start

Install
$ go get github.com/imroc/biu
Bytes to string (binary format)
bs := []byte{1, 2, 3}
s := biu.BytesToBinaryString(bs)
fmt.Println(s) //[00000001 00000010 00000011]
fmt.Println(biu.ByteToBinaryString(byte(3))) //00000011
Any data type to string (binary format)
fmt.Println(biu.ToBinaryString(3)) //[00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000011]
fmt.Println(biu.ToBinaryString(int8(4))) //00000100
fmt.Println(biu.ToBinaryString(uint16(2))) //[00000000 00000010]
fmt.Println(biu.ToBinaryString([]byte{1, 2, 3})) //[00000001 00000010 00000011]
String (binary format) to bytes
s := "[00000011 10000000]"
bs := biu.BinaryStringToBytes(s)
fmt.Printf("%#v\n", bs) //[]byte{0x3, 0x80}
String (binary format) to any data type
var a uint8
biu.ReadBinaryString("00000010", &a)
fmt.Println(a) //2

var b int16
biu.ReadBinaryString("[1 0000 0011]", &b)
fmt.Println(b) //259

LICENSE

biu is is distributed under the terms of the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBadStringFormat = errors.New("bad string format")

ErrBadStringFormat represents a error of input string's format is illegal .

View Source
var ErrEmptyString = errors.New("empty string")

ErrEmptyString represents a error of empty input string.

View Source
var ErrTypeUnsupport = errors.New("data type is unsupported")

Functions

func BinaryStringToBytes

func BinaryStringToBytes(s string) (bs []byte)

BinaryStringToBytes get the binary bytes according to the input string which is in binary format.

func ByteToBinaryString

func ByteToBinaryString(b byte) string

ByteToBinaryString get the string in binary format of a byte or uint8.

func BytesToBinaryString

func BytesToBinaryString(bs []byte) string

BytesToBinaryString get the string in binary format of a []byte or []int8.

func ReadBinaryString

func ReadBinaryString(s string, data interface{}) (err error)

ReadBinaryString read the string in binary format into input data.

func ToBinaryString

func ToBinaryString(v interface{}) (s string)

ToBinaryString get string in binary format according to input data. The input data can be diffrent kinds of basic data type.

func ToHexString

func ToHexString(v interface{}) (s string)

ToHexString get string in Hexadecimal format according to input data. The input data can be diffrent kinds of basic data type.

func ToOctalString

func ToOctalString(v interface{}) (s string)

ToOctalString get string in octal format according to input data. The input data can be diffrent kinds of basic data type.

func Uint16ToBinaryString

func Uint16ToBinaryString(i uint16) string

Uint16ToBinaryString get the string of a uint16 number in binary format.

func Uint32ToBinaryString

func Uint32ToBinaryString(i uint32) string

Uint32ToBinaryString get the string of a uint32 number in binary format.

func Uint64ToBinaryString

func Uint64ToBinaryString(i uint64) string

Uint64ToBinaryString get the string of a uint64 number in binary format.

Types

This section is empty.

Jump to

Keyboard shortcuts

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