An open API service indexing awesome lists of open source software.

https://github.com/heppu/binary-pad

Zero padding for binary format
https://github.com/heppu/binary-pad

formatter go

Last synced: about 1 year ago
JSON representation

Zero padding for binary format

Awesome Lists containing this project

README

          

# Zero padding for binary format

I often find myself writing zero padding when debugging binary data because comparing alligned binary strings in terminal is just easier than looking some messy binanry data.

##Usage

```go
package main

import (
"fmt"
"github.com/heppu/binary-pad"
"math/rand"
"time"
)

const BUF_LEN = 5

func main() {
rand.Seed(time.Now().UnixNano())
buf := make([]byte, BUF_LEN)
readBytesFromDevice(&buf)

// Print buffer zero padded
for _, v := range buf {
fmt.Println(pad.Pad(v))
}
}

// Fake reading data from device
func readBytesFromDevice(b *[]byte) {
for i := 0; i < BUF_LEN; i++ {
(*b)[i] = byte(rand.Intn(int(^uint8(0))))
}
}
```