Logo

Programming-Idioms

History of Idiom 142 > diff from v2 to v3

Edit summary for version 3 by programming-idioms.org:
New Go implementation by user [programming-idioms.org]

Version 2

2016-08-14, 16:24:22

Version 3

2016-08-14, 16:29:47

Idiom #142 Hexadecimal digits of an integer

Assign to string s the hexadecimal representation (base 16) of integer x.

E.g. 999 -> "3e7"

Idiom #142 Hexadecimal digits of an integer

Assign to string s the hexadecimal representation (base 16) of integer x.

E.g. 999 -> "3e7"

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

This works because *big.Int implements the fmt.Formatter interface.

%x is the "verb" for base 16. Not to be confused with the variable name x.
Doc URL
https://golang.org/pkg/fmt/#pkg-overview
Demo URL
https://play.golang.org/p/uFsFFhG4Ql