I see it's simple to convert golang's big int (math/big package) to a string, but is there any straightforward way of converting a big int to a binary string?
2
-
What is a binary string? – Paul Hankin Apr 27 '14 at 7:30
-
@Anonymous A string of the form 10110101011010010101010 I guess. – fuz Apr 27 '14 at 9:11
Add a comment
|
Should be as easy as this:
i := big.NewInt(2014)
s := fmt.Sprintf("%b", i) // 11111011110
fmt.Println(s)
Hope this is what you are looking for.
-
4The reason why this works is that
big.Int
implements theFormatter
interface. – nemo Apr 27 '14 at 19:49 -
1Actually,
*big.Int
(pointer type) implements theFormatter
interface :) – Deleplace Aug 21 '15 at 13:58