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/recipe01.
  2. Navigate to the directory.
  3. Create the main.go file with the following content:
        package main        import (          "fmt"          "strconv"        )        const bin = "00001"        const hex = "2f"        const intString = "12"        const floatString = "12.3"        func main() {          // Decimals          res, err := strconv.Atoi(intString)          if err != nil {            panic(err)          }          fmt.Printf("Parsed integer: %d\n", res)          // Parsing hexadecimals          res64, err := strconv.ParseInt(hex, 16, 32)          if err != nil {            panic(err)          }          fmt.Printf("Parsed hexadecima: %d\n", res64)          // Parsing binary values          resBin, err := strconv.ParseInt(bin, 2, 32)          if err != nil {            panic(err)          }          fmt.Printf("Parsed bin: %d\n", resBin)          // Parsing floating-points resFloat, err := strconv.ParseFloat(floatString, ...

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