all. I'm encountering what seems to be a very strange problem. (It could be that it's far past when I should be asleep, and I'm overlooking something obvious.)
I have a []byte
with length 8 as a result of some hex decoding. I need to produce a uint64
in order to use it. I have tried using binary.Uvarint()
, from encoding/binary
to do so, but it seems to only use the first byte in the array. Consider the following example.
package main
import (
"encoding/binary"
"fmt"
)
func main() {
array := []byte{0x00, 0x01, 0x08, 0x00, 0x08, 0x01, 0xab, 0x01}
num, _ := binary.Uvarint(array[0:8])
fmt.Printf("%v, %x
", array, num)
}
Here it is on play.golang.org.
When that is run, it displays the num
as 0
, even though, in hex, it should be 000108000801ab01
. Furthermore, if one catches the second value from binary.Uvarint()
, it is the number of bytes read from the buffer, which, to my knowledge, should be 8, even though it is actually 1.
Am I interpreting this wrong? If so, what should I be using instead?
Thanks, you all. :)