How do I convert a uint32
into an int
in Go?
A little background, I'm reading from a file and this gives me the correct size from a byte array like this:
size := binary.BigEndian.Uint32(b[4:])
However, the bufio.Discard
func expects an int. I was able to use fmt to convert size to a string and then use strconv to get it to an int. There has to be a more elegant way to do this.
The Go Programming Language Specification
Conversions
Conversions are expressions of the form
T(x)
whereT
is a type andx
is an expression that can be converted to typeT
.
For example,
size := binary.BigEndian.Uint32(b[4:])
n, err := rdr.Discard(int(size))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With