Menu Close

Go – Program to convert decimal number to hexadecimal in go

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

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

Input: num = 10
hexadecimal number = a

Input: num = 4
hexadecimal number = 4

Input: num = 15
hexadecimal number = f

Code:

package main

import (

  "fmt"
  "strconv"
)

func main() {

  var num int64

  num = 10

  hex_num := strconv.FormatInt(num, 16)

  fmt.Println("hexadecimal num: ", hex_num)


  num = 4

  hex_num = strconv.FormatInt(num, 16)

  fmt.Println("hexadecimal num: ", hex_num)


  num = 15

  hex_num = strconv.FormatInt(num, 16)

  fmt.Println("hexadecimal num: ", hex_num)

}

Output:

hexadecimal num: a

hexadecimal num: 4

hexadecimal num: f

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

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

References:

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

Posted in golang, golang program

Leave a Reply

Your email address will not be published. Required fields are marked *