Use [] to find tag! Example: [flutter, javascript]

Learn Go Programming Language
Learn Go Programming Language

Chapter 5.1

Integer Data Type

remove_red_eye 1118 Times
spellcheck 218 Words, 1565 Characters
*Note: this book is still ongoing until it has a finished label.

In Golang, an integer is a data type used to represent whole numbers. This data type allows us to work with whole numbers without decimals, such as counting the quantity of items or indices in a list. There are two main categories of integers in Golang: unsigned integers and signed integers.

Unsigned Integer

In Golang, the term "unsigned" is used to refer to an integer data type that only stores non-negative values (zero and positive numbers) and does not provide space to store negative values. Unsigned integer data types are denoted as "uint" (unsigned integer).

Here is a cheat sheet of the usage of unsigned integer data types in Golang.

Data Type NameBit SizeValue Range
uint880 until 255
uint16160 until 65535
uint32320 until 4294967295
uint64640 until 18446744073709551615

Unsigned Integer Code Example

(file main.go):

package main

import "fmt"

func main() {
	var number8 uint8
	number8 = 20
	fmt.Println(number8)
}

We can see that if we run it with:

go run main.go

Then it will produce

20

Signed Integer

In Golang, the term "integer" can represent a signed integer, which is a whole number that includes both positive and negative values.

Here is a cheat sheet of the usage of signed integer data types in Golang.

Data Type NameBit SizeValue Range
int880 until 255
int16160 until 65535
int32320 until 4294967295
int6464

0 until 18446744073709551615

Contoh Kode Signed Integer


(file main.go):

package main

import "fmt"

func main() {
	var number8 int8
	number8 = 20
	fmt.Println(number8)
}

We can see that if we run it with:

go run main.go

Then it will produce

20
Next Article (Installation)
Content Navigation