Numeral Systems - Hexadecimal

Part of Golang Mastery course

~15 min read
Interactive
Hands-on
Beginner-friendly

Numeral Systems - Hexadecimal#

example.go
package main
 
import string">"fmt"
 
func main() {
string">"comment">// fmt.Printf(string">"%d - %b - %x \n", 42, 42, 42)
string">"comment">// fmt.Printf(string">"%d - %b - %#x \n", 42, 42, 42)
string">"comment">// fmt.Printf(string">"%d - %b - %#X \n", 42, 42, 42)
fmt.Printf(string">"%d \t %b \t %#X \n", 42, 42, 42)
}
 

Run in Go Playground →

Output:

42 101010 0X2A

In the above program, the annotation verb %x formats a number in hexadecimal. For example, it represents 42 as 0X2A (base 16 format).

Integer to Hexadecimal Cheatsheet:#

%x base 16, with lower-case letters for a-f %X base 16, with upper-case letters for A-F

Your Progress

5 of 103 modules
5%
Started5% Complete
Previous
SpaceComplete
Next