I am trying to store a hexadecimal string value : ex "3958ABBFEC23BD40" to uint64 which would like this:
fmt.Println(myuint64)
$ 0x3958ABBFEC23BD40
I have tried using encoding/hex, or strconv to int, etc... I couldn't find any solution.
file, err := os.Open("myfile")
if err != nil {
fmt.Println("erreur",err)
}
b := bufio.NewReader(file)
a,_ := b.Peek(16)
d, err := strconv.ParseUint(string(a), 0, 64)
if err != nil {
panic(err)
}
fmt.Printf("%d
%s
", d,string(a))
Obviously I am not getting the result expected :
$ 4132241498901298496
fcb9ca7c63ec7c5d
expected :
$ 0xfcb9ca7c63ec7c5d
using the following code, I have retrieve the good uint, but I can't convert it to hexa, unless by using strconv, but I don't wish to work with a string.
v := *(*[8]byte)(unsafe.Pointer(&d))
var final []byte = v[:]
var n uint64
buf := bytes.NewBuffer(final)
binary.Read(buf, binary.LittleEndian, &n)
fmt.Println(strconv.FormatUint(n, 16))
result : $ fcb9ca7c63ec7c5d
but as string, and expected $ fcb9ca7c63ec7c5d
type of uint64...