How can I convert an int64 into a byte array in go?

Converting between int64 and uint64 doesn’t change the sign bit, only the way it’s interpreted.

You can use Uint64 and PutUint64 with the correct ByteOrder

http://play.golang.org/p/wN3ZlB40wH

i := int64(-123456789)

fmt.Println(i)

b := make([]byte, 8)
binary.LittleEndian.PutUint64(b, uint64(i))

fmt.Println(b)

i = int64(binary.LittleEndian.Uint64(b))
fmt.Println(i)

output:

-123456789
[235 50 164 248 255 255 255 255]
-123456789

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)