package multibaseimport ()// binaryEncodeToString takes an array of bytes and returns// multibase binary representationfunc binaryEncodeToString( []byte) string { := make([]byte, len()*8)encodeBinary(, )returnstring()}// encodeBinary takes the src and dst bytes and converts each// byte to their binary rep using power reduction methodfunc encodeBinary( []byte, []byte) {for , := range {for := 0; < 8; ++ {if &(1<<uint(7-)) == 0 { [*8+] = '0' } else { [*8+] = '1' } } }}// decodeBinaryString takes multibase binary representation// and returns a byte arrayfunc decodeBinaryString( string) ([]byte, error) {iflen()&7 != 0 {// prepend the padding = strings.Repeat("0", 8-len()&7) + } := make([]byte, len()>>3)for , := 0, 0; < len(); = + 8 { , := strconv.ParseInt([:+8], 2, 0)if != nil {returnnil, fmt.Errorf("error while conversion: %s", ) } [] = byte() ++ }return , nil}
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.