gadelkareem
(Waleed Gadelkareem)
May 17, 2018, 11:39pm
1
In this code https://play.golang.org/p/UGxgwfA3uJf
package main
import (
"encoding/hex"
"fmt"
)
func main() {
decodeHex("53D6D7")
decodeHex("6CV4GC")
}
func decodeHex(s string) {
b, err := hex.DecodeString(s)
if err != nil {
fmt.Printf("error: %v\n", err)
return
}
fmt.Println(b)
}
//Output
[83 214 215]
error: encoding/hex: invalid byte: U+0056 'V'
Is there a shortcut to convert the unicode char U+0056 āVā to UTF-8 without going through the charset.DetermineEncoding
?
vitr
(Vitaliy Ryepnoy)
May 18, 2018, 12:07am
2
I think, you misuse hex.DecodeString
DecodeString expects that src contain only hexadecimal characters and that src should have an even length. If the input is malformed, DecodeString returns a string containing the bytes decoded before the error.
In your example, how is V a hex char?
1 Like
gadelkareem
(Waleed Gadelkareem)
May 18, 2018, 12:17am
3
You right! It is not, I just had some bad hashes.
system
(system)
Closed
August 16, 2018, 12:17am
4
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.