bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/Go/Go Tutorial
Go•Go Tutorial

Go Integer Data Types

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind Go Integer Data Types?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

___ main
3Order

Put the learning moves in the order that makes the concept easiest to apply.

Integer data types are used to store a whole number without decimals, like 35, -50, or 1345000.
Which Integer Type to Use?
Go Integer Data Types

Integer data types are used to store a whole number without decimals, like 35, -50, or 1345000.

The integer data type has two categories:

  • Signed integers - can store both positive and negative values
  • Unsigned integers - can only store non-negative values

Tip

The default type for integer is int . If you do not specify a type, the type will be int .

Signed Integers

Signed integers, declared with one of the int keywords, can store both positive and negative values:

Example

package main
import ("fmt")
func main() {
  var x int = 500
  var y int = -4500
  fmt.Printf("Type: %T, value: %v", x, x)
  fmt.Printf("Type: %T, value: %v", y, y)
}

Go has five keywords/types of signed integers:

TypeSizeRange
intDepends on platform: 32 bits in 32 bit systems and 64 bit in 64 bit systems-2147483648 to 2147483647 in 32 bit systems and -9223372036854775808 to 9223372036854775807 in 64 bit systems
int88 bits/1 byte-128 to 127
int1616 bits/2 byte-32768 to 32767
int3232 bits/4 byte-2147483648 to 2147483647
int6464 bits/8 byte-9223372036854775808 to 9223372036854775807

Unsigned Integers

Unsigned integers, declared with one of the uint keywords, can only store non-negative values:

Example

package main
import ("fmt")
func main() {
  var x uint = 500
  var y uint = 4500
  fmt.Printf("Type: %T, value: %v", x, x)
  fmt.Printf("Type: %T, value: %v", y, y)
}

Go has five keywords/types of unsigned integers:

TypeSizeRange
uintDepends on platform: 32 bits in 32 bit systems and 64 bit in 64 bit systems0 to 4294967295 in 32 bit systems and 0 to 18446744073709551615 in 64 bit systems
uint88 bits/1 byte0 to 255
uint1616 bits/2 byte0 to 65535
uint3232 bits/4 byte0 to 4294967295
uint6464 bits/8 byte0 to 18446744073709551615

Which Integer Type to Use?

The type of integer to choose, depends on the value the variable has to store.

Example

package main
import ("fmt")
func main() {
  var x int8 = 1000
  fmt.Printf("Type: %T, value: %v", x, x)
}

Previous

Go Boolean Data Type

Next

Go Float Data Types