當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


GO Encode用法及代碼示例

GO語言"encoding/hex"包中"Encode"函數的用法及代碼示例。

用法:

func Encode(dst, src []byte) int

Encode 將 src 編碼為 dst 的 EncodedLen(len(src)) 字節。為方便起見,它返回寫入 dst 的字節數,但此值始終為 EncodedLen(len(src))。 Encode 實現十六進製編碼。

例子:

package main

import (
    "encoding/hex"
    "fmt"
)

func main() {
    src := []byte("Hello Gopher!")

    dst := make([]byte, hex.EncodedLen(len(src)))
    hex.Encode(dst, src)

    fmt.Printf("%s\n", dst)

}

輸出:

48656c6c6f20476f7068657221

相關用法


注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 Encode。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。