I have a data stream of bytes and I'd like to get array of int32 (from four bytes).
func convertCharToInt32(buffer string) []uint32 { const SIZEOF_INT32 = 4 var hh = make([]byte, 2) var cbuffer = make([]byte, len(buffer)/2) var hbuffer = make([]uint32, len(cbuffer)/SIZEOF_INT32) for i := 0; i < 28; i++ { hh[0] = buffer[i*2] hh[1] = buffer[i*2+1] if s, err := strconv.ParseUint(string(hh[:]), 16, 64); err == nil { cbuffer[i] = byte(s) } } for i := range hbuffer { hbuffer[i] = uint32(Endian.Uint32(cbuffer[i*SIZEOF_INT32 : (i+1)* SIZEOF_INT32])) } return hbuffer } buffer := "83f982d600c1caca7a6" hbuffer := convertCharToInt32(buffer) The code above seems to work, but perhaps there is a built-in function in Go that I've missed or there is a super cool hack that does that in one instruction? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.