import ( "fmt" "math/big" ) func main() { x := big.NewInt(123456789) b := x.Bytes() fmt.Printf("%v\n", b) }
import ( "bytes" "encoding/binary" "fmt" "math/big" ) func main() { x := big.NewInt(123456789) b := x.Bytes() if len(b) < 4 { b = append(make([]byte, 4-len(b)), b...) } var i int32 buf := bytes.NewReader(b) err := binary.Read(buf, binary.BigEndian, &i) if err != nil { fmt.Println("binary.Read failed:", err) } fmt.Printf("%d\n", i) }In this example, we use `binary.Read` from the standard library to convert a little-endian byte slice representing an integer into an integer value. First, we create a new big integer `x` with the value `123456789`, and then call `x.Bytes()` to convert it to a byte slice. We then reverse the byte order to big-endian using `append` and `make`. Finally, we use `binary.Read` to convert the byte slice to an integer variable `i`, which is printed to the console as `825373492`. Overall, the `Int.Bytes()` function is part of the `math/big` package in Go.