buf := make([]byte, 1024) reqLen, err := conn.Read(buf) // 遍历, 转为16进制 buffer := new(bytes.Buffer) for _, b := range buf[:reqLen] { s := strconv.FormatInt(int64(b&0xff), 16) if len(s) == 1 { buffer.WriteString("0") } buffer.WriteString(s) } // 转化为字符串 fmt.Println(buffer.String())