Strconv package
func parseInt
func ParseInt(s string, base int, bitSize int) (i int64, err error)
ParseInt interprets the string s in this database (from 2 to 36) and returns the corresponding value i. If base == 0, the base is the string prefix: base 16 for "0x", base 8 for "0" and base 10 otherwise.
The bitSize argument specifies the integer type to fit into. Bit sizes 0, 8, 16, 32, and 64 correspond to int, int8, int16, int32, and int64.
Errors returned by ParseInt are of specific type * NumError and include err.Num = s. If s is empty or contains invalid digits, err.Err = ErrSyntax; if the value corresponding to s cannot be represented by an integer with a sign of a given size, err.Err = ErrRange.
ParseInt always returns an int64 value. Depending on bitSize this value will correspond to int , int8 , int16 , int32 or int64 . If the value cannot be represented as an integer with the size sign specified by bitSize , then err.Err = ErrRange .
Go programming language specification
Numeric types
The value of an n-bit integer is n bits and is represented using two arithmetic.
int8 the set of all signed 8-bit integers (-128 to 127) int16 the set of all signed 16-bit integers (-32768 to 32767) int32 the set of all signed 32-bit integers (-2147483648 to 2147483647) int64 the set of all signed 64-bit integers (-9223372036854775808 to 9223372036854775807)
There is also a set of predefined numeric types with specific implementation sizes:
uint either 32 or 64 bits int same size as uint
int - 32 or 64 bits, depending on the implementation. Usually these are 32 bits for 32-bit compilers and 64 bits for 64-bit compilers.
To find out the size of int or uint , use strconv.IntSize .
Strconv package
Constants
const IntSize = intSize
IntSize is the bit size of the int or uint value.
For example,
package main import ( "fmt" "runtime" "strconv" ) func main() { fmt.Println(runtime.Compiler, runtime.GOARCH, runtime.GOOS) fmt.Println(strconv.IntSize) }
Output:
gc amd64 linux 64