That depends on what's your machine's architecture (32- or 64-bit) and how do you want it to be encoded (little- or big-endian). Either way, encoding/binary
is your answer:
var u uintptr = 42
size := unsafe.Sizeof(u)
b := make([]byte, size)
switch size {
case 4:
binary.LittleEndian.PutUint32(b, uint32(u))
case 8:
binary.LittleEndian.PutUint64(b, uint64(u))
default:
panic(fmt.Sprintf("unknown uintptr size: %v", size))
}
Playground: http://play.golang.org/p/tIocqy-rAJ.