Skip to content

Instantly share code, notes, and snippets.

@drborges
Created February 19, 2016 19:21
Show Gist options
  • Select an option

  • Save drborges/3b7e5708a4d634d74eaf to your computer and use it in GitHub Desktop.

Select an option

Save drborges/3b7e5708a4d634d74eaf to your computer and use it in GitHub Desktop.
Spikes on the encoding/binary and encoding/hex packages
package main
import "fmt"
import "encoding/binary"
import "encoding/hex"
func main() {
num := uint64(120123)
size := binary.Size(num)
fmt.Printf("size: %v\n", size)
packet := make([]byte, size)
binary.BigEndian.PutUint64(packet, num)
fmt.Printf("packet: %v\n", packet)
fmt.Printf("hex: %v\n", hex.EncodeToString(packet))
decoded := binary.BigEndian.Uint64(packet)
fmt.Printf("decoded: %v\n", decoded)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment