Reputation: 1568
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?
Upvotes: 5
Views: 3623
Reputation: 257
Use Text function
num := big.NewInt(8)
fmt.Println(num.Text(2)) // 1000
Upvotes: 0
Reputation: 17433
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.
Upvotes: 13