mardi 31 mars 2015

encoding/hex: invalid byte: U+0068 'h' Golang

I'm trying to convert a string into a byte array containing its hexadecimal values, here is the code I've written:



package main

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

func main() {
str :="abcdefhijklmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ123456789"

b, err := hex.DecodeString(str)

if err != nil {
fmt.Println(err)
os.Exit(1)
}

fmt.Printf("Decoded bytes %v \n ", b)
}


Here is the link from Go PlayGround: http://ift.tt/1BGzif7


But it's giving me the error *encoding/hex: invalid byte: U+0068 'h' Golang *. What's the problem here? I want to convert my string into byte array containing hexadecimal values of each character in the string. I want b[n] to contain hexadecimal value of str[n].


Aucun commentaire:

Enregistrer un commentaire