You can simply use conversion type:
i := uint64(0xffffffffffffffff) i2 := int64(i) fmt.Println(i, i2)
Output:
18446744073709551615 -1
Converting uint64 to int64 always succeeds: it does not change the memory representation of only the type. Which may confuse you if you try to convert the value of an untyped integer value to int64 :
i3 := int64(0xffffffffffffffff) // Compile time error!
This is a compile-time error, since the constant value 0xffffffffffffffff (which is represented with arbitrary precision) does not fit into int64 , because the maximum value that fits into int64 is 0x7fffffffffffffff :
constant 18446744073709551615 overflows int64
source share