I have to convert hex
, represeneted as string
s (e.g. "0xC40C5253"
) to float values (IEEE-754 conversion). I did not manage to do that using the strconv.ParseFloat function. Is there anything else I have to use?
I couldn't find it so far. I also tried converting it to an integer first and then to a float, but the results were wrong.
Code of my last try:
package main
import (
"fmt"
"strconv"
)
func main () {
x, err := strconv.ParseInt("C40C5253", 16, 64)
f, err := strconv.ParseFloat(fmt.Sprintf("%d", x), 64)
if err != nil {
fmt.Printf("Error in conversion: %s
", err)
} else {
fmt.Println(f)
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…