add BinStr() helper

master
Kevin Golding 5 years ago
parent db1fccac30
commit c6f3cc8b88

@ -4,7 +4,6 @@ import (
"fmt"
"os"
"strconv"
"strings"
pc "github.com/kgolding/go-pocsagencode"
)
@ -27,11 +26,7 @@ func main() {
}
burst, _ := pc.Generate(messages)
binStrs := []string{}
for _, b := range burst.Bytes() {
binStrs = append(binStrs, fmt.Sprintf("0b%b", b))
}
fmt.Printf("Message: %s\n\n", burst.String())
fmt.Printf("Hex bytes: % X\n\n", burst.Bytes())
fmt.Printf("Binary: %s\n\n", strings.Join(binStrs, ", "))
fmt.Printf("Binary: %s\n\n", burst.BinStr())
}

@ -3,6 +3,7 @@ package pocsagencode
import (
"encoding/binary"
"fmt"
"strings"
)
type Burst []uint32
@ -38,3 +39,12 @@ func (b Burst) Bytes() []byte {
}
return buf
}
// BinStr returns a binary string split into bytes
func (b Burst) BinStr() string {
binStrs := []string{}
for _, b := range b.Bytes() {
binStrs = append(binStrs, fmt.Sprintf("0b%b", b))
}
return strings.Join(binStrs, ", ")
}

@ -1,8 +1,6 @@
package pocsagencode
import (
"fmt"
"strings"
"testing"
)
@ -35,11 +33,4 @@ func Test_Encode(t *testing.T) {
}
}
}
t.Log(enc)
t.Log(enc.Bytes())
binStrs := []string{}
for _, b := range enc.Bytes() {
binStrs = append(binStrs, fmt.Sprintf("0b%b", b))
}
t.Log(strings.Join(binStrs, ", "))
}

Loading…
Cancel
Save