Example of converting hexadecimal to integer in Go

This is an example Go program for hexadecimal-to-integer.

package main

import (
        "fmt"
        "strconv"
)

func main() {
        hex := "beef"
        value, err := strconv.ParseInt(hex, 16, 64)
        if err != nil {
                fmt.Printf ("Conversion failed: %s\n", err)
        } else {
                fmt.Printf ("Hexadecimal '%s' is integer %d (%X)",
                        hex, value, value)
        }
}

(download)

The output of the example looks like this:

Hexadecimal beef is integer 48879 (BEEF)


Copyright © Ben Bullock 2009-2017. All rights reserved. For comments, questions, and corrections, please email Ben Bullock (benkasminbullock@gmail.com). / Privacy / Disclaimer