Logo

Programming-Idioms

History of Idiom 76 > diff from v5 to v6

Edit summary for version 6 by :

Version 5

2015-08-21, 13:46:48

Version 6

2015-08-21, 13:56:56

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"
Imports
import "fmt"
import "math/big"
Code
s := fmt.Sprintf("%b", x)
Code
s := fmt.Sprintf("%b", x)
Comments bubble
x has type *big.Int.

This works because big.Int implements the fmt.Formatter interface.
Comments bubble
x has type *big.Int.

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