The fmt package allows us to print a binary representation of integers with %b. How to get an equivalent result for floats instead of the scientific notation?
fmt.Printf("%b", 52) // 110100
fmt.Printf("%b", 52.0) // 7318349394477056p-47
The fmt package allows us to print a binary representation of integers with %b. How to get an equivalent result for floats instead of the scientific notation?
fmt.Printf("%b", 52) // 110100
fmt.Printf("%b", 52.0) // 7318349394477056p-47
You can get the raw bits of a float with the math
package using math.Float64bits
or math.Float32bits
. Combining this with the %b
formatting verb will display the binary representation of the float.
fmt.Printf("%b
", math.Float64bits(52.0))