Decoding data from a byte slice to Uint32
go
Solution
You can do this with one of the `ByteOrder` objects from the `encoding/binary` package. For instance:
package main
import (
"encoding/binary"
"fmt"
)
func main() {
aa := uint(0x7FFFFFFF)
fmt.Println(aa)
slice := []byte{0xFF, 0xFF, 0xFF, 0x7F}
tt := binary.LittleEndian.Uint32(slice)
fmt.Println(tt)
}
If your data is in big endian format, you can instead use the same methods on `binary.BigEndian`.
Problem
``` package main import ( "bytes" "encoding/binary" "fmt" ) func main() { aa := uint(0xFFFFFFFF) fmt.Println(aa) byteNewbuf := []byte{0xFF, 0xFF, 0xFF, 0xFF} buf := bytes.NewBuffer(byteNewbuf) tt, _ := binary.ReadUvarint(buf) fmt.Println(tt) } ``` Need to convert 4 bytes array to uint32 but why the results are not same ? go verion : beta 1.1