go - Decoding data from a byte slice to Uint32 -


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 convert 4 bytes array uint32 why results not same ? go verion : beta 1.1

you can 1 of byteorder objects encoding/binary package. 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 data in big endian format, can instead use same methods on binary.bigendian.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -