Menu Close

Go – Program to convert octal number to decimal in go

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

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

Input: octal num = 10
Decimal number = 8

Input: octal num = 4
Decimal number = 4

Input: octal num = 15
Decimal number = 13

Code:

package main

import (

  "fmt"
  "strconv"
)

func main() {

  oct_num := "10"

  num, err := strconv.ParseInt(oct_num, 8, 64)

  if err != nil {

    panic(err)

  }

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


  oct_num = "4"

  num, err = strconv.ParseInt(oct_num, 8, 64)

  if err != nil {

    panic(err)

  }

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


  oct_num = "15"

  num, err = strconv.ParseInt(oct_num, 8, 64)

  if err != nil {

    panic(err)

  }

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

Output:

decimal num: 8

decimal num: 4

decimal num: 13

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

Leave a Reply

Your email address will not be published.

Contact Us