相当于Python中的decode('hex')

2024-10-03 23:18:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在将一个现有的Python库转换为Go,并且正在处理一个问题。你知道吗

有没有一个go等价于下面的Python代码?你知道吗

test = "ec033aa702"
test.decode('hex')

我一直在看书,但似乎找不到我要找的东西。你知道吗


Tags: 代码testgodecodehex等价ec033aa702
1条回答
网友
1楼 · 发布于 2024-10-03 23:18:37

这对你有用吗?你知道吗

package main

import (
  "encoding/hex"
  "fmt"
  "log"
)

func main() {
  const s = "ec033aa702"
  decoded, err := hex.DecodeString(s)
  if err != nil {
    log.Fatal(err)
  }

  fmt.Printf("%s\n", decoded)
}

DecodeString

Try it online!

相关问题 更多 >