Logo

Programming-Idioms

History of Idiom 76 > diff from v3 to v4

Edit summary for version 4 by :

Version 3

2015-08-21, 13:38:27

Version 4

2015-08-21, 13:45:32

Idiom #76 Binary digits from an integer

Create the string s of integer x written in base 2.

E.g. 13 -> "1101"

Idiom #76 Binary digits from an integer

Create the string s of integer x written in base 2.

E.g. 13 -> "1101"

Imports
import "fmt"
import "math/big"
Code
s := fmt.Sprintf("%b", x)
Comments bubble
x has type *big.Int.

This works because big.Int implements the fmt.Formatter interface.
Origin
http://stackoverflow.com/a/23317788/871134
Demo URL
http://play.golang.org/p/2Oy1pcgGZU