Mugs9117
Mugs9117

Reputation: 61

Go equivalent of decode('hex') in Python

I'm working on converting an existing Python library to Go and am getting hung up on a piece.

Is there a go equivalent to the following Python code?

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

I've been doing some reading but can't seem to find what I'm looking for.

Upvotes: 2

Views: 429

Answers (1)

Doug Coburn
Doug Coburn

Reputation: 2575

Does this work for you?

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!

Upvotes: 1

Related Questions