Posted on 2013-08-02 10:13
oathleo 阅读(496)
评论(0) 编辑 收藏 所属分类:
Golang
windows下字节序和网络的相反
func readInt32(conn net.Conn) int32 {
num_byte := make([]byte, 4)
conn.Read(num_byte)
var value int32 = 0
// //windows
// byte2 := num_byte[2]
// byte3 := num_byte[3]
// num_byte[3] = num_byte[0]
// num_byte[0] = byte3
// num_byte[2] = num_byte[1]
// num_byte[1] = byte2
// //windows
//windows
num_byte[0],num_byte[1],num_byte[2],num_byte[3] = num_byte[3],num_byte[2],num_byte[1],num_byte[0]
for i := 0; i < 4; i++ {
shift := uint32((4 - 1 - i) * 8)
value = value + (int32(num_byte[i])&0x000000FF)<<shift
}
return value
}