To convert a number from base 10 to base 2 (binary) in Go, we can use the strconv package.
Here's an example code snippet:
main.go305 chars18 lines
In this code, we first import the "fmt" and "strconv" packages.
decimalToBinary()
function takes an integer of base 10 and converts it to a binary string using strconv.FormatInt()
function.
And finally, in the main()
function, we call decimalToBinary()
function with input of type int64 and print the output.
Output of the above code snippet will be:
main.go26 chars2 lines
gistlibby LogSnag