Question:
Is there a built-in function in Go that can convert numeric types into their binary number form?
For instance, if we provide 123 as input, we should obtain the string "1111011" as output.
Answer:
Yes, there is an inbuilt function called strconv.FormatInt in the strconv package that can convert integers into their binary representation.
n := int64(123) fmt.Println(strconv.FormatInt(n, 2)) // 1111011
This FormatInt function takes two parameters: an int64 and a base. The base specifies the base of the numerical representation.
Example:
Documentation:
strconv.FormatInt function:
The above is the detailed content of How to Convert Integers to Binary Representation in Go?. For more information, please follow other related articles on the PHP Chinese website!