Menu Close

# Go – Program to convert hexadecimal number to decimal in go

Here, we will see program to convert hexadecimal number to decimal in go. Given below, you can find algorithm and program.

To convert hexadecimal number to decimal number, we will use ParseInt() function of strconv package.

```Input:Â hexadecimal num = ab1
Decimal number = 2737

Input:Â hexadecimal num = 12
Decimal number = 18

Input:Â hexadecimal num = ffff
Decimal number = 65535```

Code:

```package main

import (

"fmt"
"strconv"
)

func main() {

hex_num := "ab1"

num, err := strconv.ParseInt(hex_num, 16, 64)

if err != nil {

panic(err)

}

fmt.Println("decimal num: ", num)

hex_num = "12"

num, err = strconv.ParseInt(hex_num, 16, 64)

if err != nil {

panic(err)

}

fmt.Println("decimal num: ", num)

hex_num = "ffff"

num, err = strconv.ParseInt(hex_num, 16, 64)

if err != nil {

panic(err)

}

fmt.Println("decimal num: ", num)

}
```

Output:

```decimal num: 2737

decimal num: 18

decimal num: 65535```

To learn more about golang. Please follow given below link.

`https://www.techieindoor.com/go-lang/`

References:

```https://golang.org/doc/
https://golang.org/pkg/```

Posted in golang, golang program