Numeral Systems - Binary#
example.go
package mainimport string">"fmt"func main() {fmt.Printf(string">"%d - %b \n", 42, 42)}
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"