I'm trying with Go to get values of KiB, MiB, ..., ZiB, Yib
which are respectively KibiByte, MebiByte, ..., ZebiByte, YobiByte
.
My code in Golang is:
package main
import (
"fmt"
)
func main() {
s := []string{"KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"}
for k,v := range(s) {
fmt.Printf("%s: %v
", v, 1 << uint64(10 * (k+1)))
}
}
But, the values of ZiB and YiB
overflows Go uint64
and this why I'm having this output:
KiB: 1024
MiB: 1048576
GiB: 1073741824
TiB: 1099511627776 // exceeds 1 << 32
PiB: 1125899906842624
EiB: 1152921504606846976
ZiB: 0 // exceeds 1 << 64
YiB: 0 // exceeds 1 << 64
Otherwise, with the same shifting logic in Python3
within this code:
a = ["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"]
for k,v in enumerate(a):
print("{}: {}".format(v, 1 << (10 *(k+1))))
The output is correct, like the output below:
KiB: 1024
MiB: 1048576
GiB: 1073741824
TiB: 1099511627776
PiB: 1125899906842624
EiB: 1152921504606846976
ZiB: 1180591620717411303424
YiB: 1208925819614629174706176
So, how can I bypass Go uint64
limits and get the correct values using shifting integers like what I can get from shifting integers using Python.
Thanks.