gpt4 book ai didi

golang 如何将 uint64 转换为 int64?

转载 作者:IT王子 更新时间:2023-10-29 01:41:13 24 4
gpt4 key购买 nike

<分区>

谁能帮帮我?请将 uint64 转换为 int64

//fmt.Println(int64(18446744073709551615)) 
//constant 18446744073709551615 overflows int64

var x uint64 = 18446744073709551615
var y int64 = int64(x)
fmt.Println(y) //-1

//just like(c)signed long long
//anyone can help me pls!
//How can I using like this?

// -9223372036854775808 +9223372036854775807

func BytesToInt(b []byte) int {
bytesBuffer := bytes.NewBuffer(b)
var tmp int32
binary.Read(bytesBuffer, binary.BigEndian, &tmp)
return int(tmp)
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com