GO語言"encoding/hex"包中"Decode"函數的用法及代碼示例。
用法:
func Decode(dst, src []byte)(int, error)
Decode 將 src 解碼為 DecodedLen(len(src)) 字節,返回寫入 dst 的實際字節數。
Decode 期望 src 僅包含十六進製字符,並且 src 具有偶數長度。如果輸入格式錯誤,則 Decode 返回錯誤前解碼的字節數。
例子:
package main
import (
"encoding/hex"
"fmt"
"log"
)
func main() {
src := []byte("48656c6c6f20476f7068657221")
dst := make([]byte, hex.DecodedLen(len(src)))
n, err := hex.Decode(dst, src)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", dst[:n])
}
輸出:
Hello Gopher!
相關用法
- GO DecodeLastRuneInString用法及代碼示例
- GO Decoder.Token用法及代碼示例
- GO Decoder.Decode用法及代碼示例
- GO DecodeRuneInString用法及代碼示例
- GO DecodeRune用法及代碼示例
- GO Decoder用法及代碼示例
- GO DecodeLastRune用法及代碼示例
- GO DecodeString用法及代碼示例
- GO DumpResponse用法及代碼示例
- GO DB.QueryRowContext用法及代碼示例
- GO Date用法及代碼示例
- GO DB.ExecContext用法及代碼示例
- GO Dial用法及代碼示例
- GO DB.BeginTx用法及代碼示例
- GO DumpRequest用法及代碼示例
- GO Drawer用法及代碼示例
- GO Duration.Hours用法及代碼示例
- GO Duration.Round用法及代碼示例
- GO DumpRequestOut用法及代碼示例
- GO Duration用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 Decode。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。