码迷,mamicode.com
首页 > 编程语言 > 详细

Golang十六进制字符串和byte数组互转

时间:2020-04-01 20:57:43      阅读:344      评论:0      收藏:0      [点我收藏+]

标签:pack   %s   pac   运行   lock   string   odi   Golan   需求   

Golang十六进制字符串和byte数组互转

需求

Golang十六进制字符串和byte数组互相转换,使用"encoding/hex"包

实现Demo

package main

import (
	"encoding/hex"
	"fmt"
)

func main() {
	str := "ff68b4ff"
	b, _ := hex.DecodeString(str)

	encodedStr := hex.EncodeToString(b)
	fmt.Printf("@@@@--bytes-->%02x \n",b)
	fmt.Printf("@@@@--string-->%s \n",encodedStr)
}

运行结果

@@@@--string-->ff68b4ff 
@@@@--bytes-->ff68b4ff 

Golang十六进制字符串和byte数组互转

标签:pack   %s   pac   运行   lock   string   odi   Golan   需求   

原文地址:https://www.cnblogs.com/Kingram/p/12615667.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!