LoginSignup
2

More than 5 years have passed since last update.

uint64型を[]bytes型に変換する

Posted at

日本語の記事が見つからなかったのでメモしておきます.

こちらを参考にしました.

enconding/binaryパッケージのPutUint64メソッドでuint64型から[]bytes型に変換出来ます.

コード例

package main

import (
    "fmt"
    "encoding/binary"
)

func main() {
    u := uint64(1000)
    b := make([]byte, 8)
    binary.LittleEndian.PutUint64(b, u)
    fmt.Printf("%T:%v  %T:%v", u, u, b, b)
}

実行結果

uint64:1000  []uint8:[232 3 0 0 0 0 0 0]

まとめ

encoding/binaryパッケージを使うことで,uint64型を[]bytes型に変換できます.

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2