/bit-on-bytes

bitwise operation on []byte

Primary LanguageGo

bit-on-bytes

bitwise operation on []byte

To test:

package main

import ( "github.com/yhzhao/bit-on-bytes" "log" "strconv" )

func printByte(a byte) string { //log.Println(strconv.Itoa(int(a)) + "|") return strconv.Itoa(int(a)) + "|" }

func PrintByte(a byte) string { //log.Println(strconv.Itoa(int(a))) return strconv.Itoa(int(a)) }

func PrintBytes(a []byte) string { out := "" for i := 0; i < len(a); i++ { out = out + printByte(a[i]) } log.Println(out) return out }

func main() { a := make([]byte, 4) a[0] = 1 a[3] = 2 //log.Println(a[0]) //log.Println(string(a)) PrintBytes(a) b, holder, _ := bitonbytes.ShiftByte(a, 1) //log.Println(string(b)) PrintBytes(b) PrintBytes(holder) b, holder, _ = bitonbytes.ShiftByte(a, -1) PrintBytes(b) PrintBytes(holder) }