O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

  1. Open the console and create the folder chapter03/recipe06.
  2. Navigate to the directory.
  3. Create the convert.go file with the following content:
        package main        import (          "fmt"          "strconv"        )        const bin = "10111"        const hex = "1A"        const oct = "12"        const dec = "10"        const floatNum = 16.123557        func main() {          // Converts binary value into hex          v, _ := ConvertInt(bin, 2, 16)          fmt.Printf("Binary value %s converted to hex: %s\n", bin, v)          // Converts hex value into dec          v, _ = ConvertInt(hex, 16, 10)          fmt.Printf("Hex value %s converted to dec: %s\n", hex, v)          // Converts oct value into hex          v, _ = ConvertInt(oct, 8, 16)          fmt.Printf("Oct value %s converted to hex: %s\n", oct, v)          // Converts dec value into oct          v, _ = ConvertInt(dec, 10, 8) fmt.Printf("Dec ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required