library: encoding/hex

This commit is contained in:
xushiwei
2024-07-30 00:33:44 +08:00
parent ad1a42d6a5
commit 679e2d0f6b
2 changed files with 13 additions and 0 deletions

View File

@@ -292,6 +292,7 @@ Here are the Go packages that can be imported correctly:
* [reflect](https://pkg.go.dev/reflect) (partially)
* [time](https://pkg.go.dev/time) (partially)
* [encoding/binary](https://pkg.go.dev/encoding/binary)
* [encoding/hex](https://pkg.go.dev/encoding/hex)
* [encoding/base32](https://pkg.go.dev/encoding/base32)
* [encoding/base64](https://pkg.go.dev/encoding/base64)
* [regexp](https://pkg.go.dev/regexp)

View File

@@ -3,7 +3,9 @@ package main
import (
"encoding/base32"
"encoding/base64"
"encoding/hex"
"fmt"
"log"
)
func base64Demo() {
@@ -30,7 +32,17 @@ func base32Demo() {
fmt.Printf("%q\n", dst)
}
func hexDemo() {
const s = "48656c6c6f20476f7068657221"
decoded, err := hex.DecodeString(s)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", decoded)
}
func main() {
base64Demo()
base32Demo()
hexDemo()
}