LoginSignup
1
0

More than 5 years have passed since last update.

Golangの[]byteを初期化するときにintを変数で含めたい

Last updated at Posted at 2016-06-17
i := 1
b := []byte{0x00, 0x01, i}

とすると

$ go build
cannot use i (type int) as type byte in append

と怒られる。どうやら型がだめらしい。

i := 1
b := []byte{0x00, 0x01, uint8(i)}

とすれば大丈夫。

なにこれ地味にはまった。。。

1
0
1

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
1
0