Programming-Idioms

History of Idiom 76 > diff from v33 to v34

Edit summary for version 34 :
[Go]+DocURL to package fmt

Version 33

2015-12-18, 03:14:48

Version 34

2015-12-30, 13:57:44

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.
Doc URL
https://golang.org/pkg/fmt/#pkg-overview
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