I have created a program which converts int64 to binary:
package main
import (
"fmt"
"strconv"
)
func main() {
n := int64(3)
fmt.Println(strconv.FormatInt(n, 2))
}
And it returns this value:
11
How can I keep the leading zeros in the answer?
Thanks in advance!
You can format directly as binary with padding:
fmt.Printf("%064b\n", n)
See https://play.golang.org/p/JHCgyPMKDG
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With