From be9178df09d8e517ebb2fa7435f019618f0f4bd4 Mon Sep 17 00:00:00 2001 From: Gowtham Gopalakrishnan Date: Sun, 17 Feb 2019 12:13:57 +0530 Subject: [PATCH] changed shifting logic --- base2.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/base2.go b/base2.go index e4e5ed2..6e3f0cf 100644 --- a/base2.go +++ b/base2.go @@ -2,7 +2,6 @@ package multibase import ( "fmt" - "math" "strconv" "strings" ) @@ -18,15 +17,12 @@ func binaryEncodeToString(src []byte) string { // encodeBinary takes the src and dst bytes and converts each // byte to their binary rep using power reduction method func encodeBinary(dst []byte, src []byte) { - for i := 0; i < len(src); i++ { - t := src[i] - for j := i << 3; j < (i<<3)+8; j++ { - higherPower := math.Pow(2, float64(7-(j&7))) - if t >= byte(higherPower) { - dst[j] = '1' - t = t - byte(higherPower) + for i, b := range src { + for j := 0; j < 8; j++ { + if b&(1<