I would like to convert the variable in [ ]uint to [ ]byte.
Is there a good solution...?
As the questions are unclear, the answers will vary depending on the results.
As Nobonobo said, please convert it into a loop
The result is 1, 2, 3, and 4 bytes slices.
It depends on the endian.The results depend on how uint (uint32 or uint64) is stored in memory.The following is an example of a Big Endian used as a network byte order:
The result is
[00 0 1 0 2 0 3 0 4 ].The size of uint varies depending on the platform, so if you can decide the size from the beginning, you can write it as follows.
© 2022 OneMinuteCode. All rights reserved.