Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Golang Big Integers to Binary String

Tags:

go

biginteger

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?

like image 536
tonyl7126 Avatar asked Dec 19 '22 15:12

tonyl7126


1 Answers

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.

like image 90
Sebastian Avatar answered Jan 10 '23 23:01

Sebastian