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
- Host: GitHub
- URL: https://github.com/heppu/binary-pad
- Owner: heppu
- License: mit
- Created: 2016-07-12T21:15:21.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-07-12T21:57:24.000Z (about 10 years ago)
- Last Synced: 2025-01-04T22:45:08.059Z (over 1 year ago)
- Topics: formatter, go
- Language: Go
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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))))
}
}
```