'loop that will output in order from 1 to 5 []bytes in golang
How to make a loop that will output in order from 1 to 5 []bytes?
Here is what I need in the output:
[0]
[1]
[2]
...
[255]
[0 1]
[1 1]
[2 1]
...
etc (to max 5 bytes)
For example, if I doing a normal loop from numbers and turn them into bytes using these functions:
for i := 0; i < 8589934590; i++ {
b : intToBytes(i)
fmt.Println(b)
}
func intToBytes(val int) []byte {
r := make([]byte, 5)
for i := int(0); i < 5; i++ {
r[i] = byte((val >> (8 * i)) & 0xff)
}
return r
}
there will be extra zeros at the end of the output.
If this option is correct, then how to get rid of extra zeros?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
