Skip to content

heppu/binary-pad

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

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))))
	}
}

About

Zero padding for binary format

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages