From 3603905b6fad2ccd447d9a6d8f66a8edc3658b62 Mon Sep 17 00:00:00 2001 From: Wijnand Modderman-Lenstra Date: Wed, 9 Dec 2015 01:03:39 +0100 Subject: [PATCH] bit: added .Equal() and .Len() --- bit/bit.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/bit/bit.go b/bit/bit.go index 9b505d5..67e0cea 100644 --- a/bit/bit.go +++ b/bit/bit.go @@ -38,9 +38,26 @@ func (bits *Bits) Bytes() []byte { return o } -func (bits *Bits) String() string { +func (bits Bits) Equal(other Bits) bool { + var l = bits.Len() + if l != other.Len() { + return false + } + for i := 0; i < l; i++ { + if bits[i] != other[i] { + return false + } + } + return true +} + +func (bits Bits) Len() int { + return len(bits) +} + +func (bits Bits) String() string { var s = "" - for _, b := range *bits { + for _, b := range bits { if b == 0x01 { s += "1" } else {