package main
import "fmt"
func main() {
x := 405940594059
fmt.Printf("%b\n", x) // 1011110100000111111000111100101100010111
fmt.Printf("%o\n", x) // 5720374362613
fmt.Printf("%x\n", x) // 5E83F1E58B
fmt.Printf("%U\n", x) // U+5E83F1E58B
}
integer:
%b base 2
%c the character represented by the corresponding Unicode code point
%d base 10
%o base 8
%O base 8 with 0o prefix
%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"
package main
import "fmt"
func main() {
x := 405940594059
xAsBinary := fmt.Sprintf("%b\n", x) // 1011110100000111111000111100101100010111
fmt.Println(x, xAsBinary) // 405940594059 1011110100000111111000111100101100010111
}
String and slice of bytes (treated equivalently with these verbs):
%s the uninterpreted bytes of the string or slice
%q a double-quoted string safely escaped with Go syntax
%x base 16, lower-case, two characters per byte
%X base 16, upper-case, two characters per byte
강의 출처 : 노마드코더(https://nomadcoders.co)
[Nomad Coin] Tour of Go - #3.5 Pointers (0) | 2022.07.10 |
---|---|
[Nomad Coin] Tour of Go - #3.4 Slices and Arrays (0) | 2022.07.10 |
[Nomad Coin] Tour of Go - #3.2 functions (0) | 2022.07.10 |
[Nomad Coin] Tour of Go - #3.1 Variables in Go (0) | 2022.07.10 |
[Nomad Coin] Tour of Go - #3.0 Creating the Project (0) | 2022.07.10 |
댓글 영역