Standard library / strconv

strconv.ParseInt()

Parses signed integer text in base 0 or 2–36. Base 0 recognizes prefixes and permits Go-style underscores. bitSize 0 means int; 1–64 constrain width (8/16/32/64 match the common fixed-width integer types). Syntax errors return zero; range errors return the nearest bound and an error. Expected stdout: '127 <nil>\n'.

Formal Syntax & Structure

go syntaxgo
func ParseInt(s string, base int, bitSize int) (i int64, err error)

Parameters & Attributes

NameTypeDescription
sstringInput text to parse, inspect or quote.
baseintRadix 2–36; parsing also accepts 0 to infer the radix.
bitSizeintRequired integer width in bits; 0 selects native int/uint width.

Return Value

(i int64, err error)

Decoded or parsed value and error; inspect the error before using the result.

Working Example

Example Snippetgo
package main
import (  "fmt"  "strconv")
func main() {  v, e := strconv.ParseInt("0x7f", 0, 8)  fmt.Println(v, e)}
Go Reference