Can't understand how Go converts integers to hex
when I run this code
package main
import (
"fmt"
)
func main() {
d := -12345
hex := fmt.Sprintf("%X", d)
fmt.Println(hex)
}
I see result -3039, but I expect to see cfc7, because go uses Two’s-Complement representation
And how can I get a right answer in the output?
You are passing in an
int, which is signed. Pass an unsigned in:This will print FFFFFFFFFFFFCFC7