Numeral Systems - Binary

Part of Golang Mastery course

~15 min read
Interactive
Hands-on
Beginner-friendly

Numeral Systems - Binary#

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

Run in Go Playground →

Output:

42 - 101010 Program exited.

In the above program, the annotation verb %b formats a number in binary (which represents 101010, base 2 format) and the annotation verb %d formats a number in Base 10 (which represents 42, base 10 format).

Integer cheatsheet for fmt#

%b base 2 %c the character represented by the corresponding Unicode code point %d base 10 %o base 8 %q a single-quoted character literal safely escaped with Go syntax %x base 16, with lower-case letters for a-f %X base 16, with upper-case letters for A-F %U Unicode format: U+1234; same as "U+%04X"

Your Progress

4 of 103 modules
4%
Started4% Complete
Previous
SpaceComplete
Next