The textbook you are looking for is

The Go Programming Language Specification

Numeric types

A numeric type represents sets of integer or floating-point values. The predeclared architecture-independent numeric types are:

uint32 set of all unsigned 32-bit integers (0 to 4294967295)
uint64 set of all unsigned 64-bit integers (0 to 18446744073709551615)

int32  set of all signed 32-bit integers (-2147483648 to 2147483647)
int64  set of all signed 64-bit integers (-9223372036854775808 to 9223372036854775807)

There is also a set of predeclared numeric types with implementation-specific sizes:

uint either 32 or 64 bits
int  same size as uint

Check the size of type int. On the Go Playground it's 4 bytes or 32 bits.

package main

import (
    "fmt"
    "runtime"
    "unsafe"
)

func main() {
    fmt.Println("arch", runtime.GOARCH)
    fmt.Println("int", unsafe.Sizeof(int(0)))
}

Playground: https://play.golang.org/p/2A6ODvhb1Dx

Output (Playground):

arch amd64p32
int 4

Run the program in your (LeetCode) environment. It's likely 8 bytes or 64 bits.

For example, in my environment,

Output (Local):

arch amd64
int 8

Here are some fixes to your code,

package main

import (
    "fmt"
    "runtime"
)

func main() {
    fmt.Println(runtime.GOARCH)
    fmt.Printf("%v\n", singleNumber([]int{-2, -2, 1, 1, -3, 1, -3, -3, -4, -2}))
}

func singleNumber(nums []int) int {
    sum := make([]int, 64)

    for _, v := range nums {
        for i := range sum {
            sum[i] += 1 & (v >> uint(i))
        }
    }

    res := 0
    for k, v := range sum {
        if (v % 3) != 0 {
            res |= (v % 3) << uint(k)
        }
    }
    fmt.Printf("res %+v\n", res)
    return res
}

Playground: https://play.golang.org/p/kaoSuesu2Oj

Output (Playground):

amd64p32
res -4
-4

Output (Local):

amd64
res -4
-4
Answer from peterSO on Stack Overflow
Top answer
1 of 1
24

The textbook you are looking for is

The Go Programming Language Specification

Numeric types

A numeric type represents sets of integer or floating-point values. The predeclared architecture-independent numeric types are:

uint32 set of all unsigned 32-bit integers (0 to 4294967295)
uint64 set of all unsigned 64-bit integers (0 to 18446744073709551615)

int32  set of all signed 32-bit integers (-2147483648 to 2147483647)
int64  set of all signed 64-bit integers (-9223372036854775808 to 9223372036854775807)

There is also a set of predeclared numeric types with implementation-specific sizes:

uint either 32 or 64 bits
int  same size as uint

Check the size of type int. On the Go Playground it's 4 bytes or 32 bits.

package main

import (
    "fmt"
    "runtime"
    "unsafe"
)

func main() {
    fmt.Println("arch", runtime.GOARCH)
    fmt.Println("int", unsafe.Sizeof(int(0)))
}

Playground: https://play.golang.org/p/2A6ODvhb1Dx

Output (Playground):

arch amd64p32
int 4

Run the program in your (LeetCode) environment. It's likely 8 bytes or 64 bits.

For example, in my environment,

Output (Local):

arch amd64
int 8

Here are some fixes to your code,

package main

import (
    "fmt"
    "runtime"
)

func main() {
    fmt.Println(runtime.GOARCH)
    fmt.Printf("%v\n", singleNumber([]int{-2, -2, 1, 1, -3, 1, -3, -3, -4, -2}))
}

func singleNumber(nums []int) int {
    sum := make([]int, 64)

    for _, v := range nums {
        for i := range sum {
            sum[i] += 1 & (v >> uint(i))
        }
    }

    res := 0
    for k, v := range sum {
        if (v % 3) != 0 {
            res |= (v % 3) << uint(k)
        }
    }
    fmt.Printf("res %+v\n", res)
    return res
}

Playground: https://play.golang.org/p/kaoSuesu2Oj

Output (Playground):

amd64p32
res -4
-4

Output (Local):

amd64
res -4
-4
🌐
DEV Community
dev.to › herocod3r › demystifying-the-int-type-in-go-1f63
Demystifying the int type in Go - DEV Community
May 3, 2021 - func printAll(){ fmt.Printf(" int %d,\n int8 %d, \n int16 %d,\n int32 %d, \n int64 %d", unsafe.Sizeof(int(0)), unsafe.Sizeof(int8(0)), unsafe.Sizeof(int16(0)), unsafe.Sizeof(int32(0)), unsafe.Sizeof(int64(0))) } The result is · Wow, coming from a C# background where an int is always 4 byte, seeing 8bytes for an int is mind boggling.
🌐
Quora
quora.com › Should-I-use-int-or-Int32
Should I use int or Int32? - Quora
Answer (1 of 2): It depends. What are you planning to do? The Int32 looks like [code ]int32_t[/code], which has a sign bit and is exactly 32 bits long. The [code ]int[/code] has a sign bit as well, but its length varies according to used tools and system.
🌐
YourBasic
yourbasic.org › golang › int-vs-int64
Pick the right one: int vs. int64 · YourBasic Go
The int type is either 32 or 64 bits, and always big enough to hold the maximum possible length of an array. See Maximum value of an int for code to compute the maximum value of an int.
🌐
Educative
educative.io › answers › what-is-type-int32-in-golang
What is type int32 in Golang?
int is one of the available numeric data types in Go used to store signed integers. int32 is a version of int that only stores signed numeric values composed of up to 32 bits.
🌐
Sololearn
sololearn.com › en › Discuss › 2682964 › golang-int8-int16-int32-float32-
Golang int8, int16, int32, float32 .... | Sololearn: Learn to code for FREE!
because sometimes int32 or below is enough (and it could make a memory footprint very different for large dataset). however, basic use for few variable are commonly done with the widest int type available for your cpu (usualy int64 or int32 depending on platform)
Find elsewhere
🌐
Reddit
reddit.com › r/golang › using int32 for efficiency or simply stick to int64?
r/golang on Reddit: Using int32 for efficiency or simply stick to int64?
January 30, 2022 -

I have a field in my data which is small enough to simply use an int32. However, from what I can tell, int32 is generally used when representing a code point or something quite specific, rather than using it simply to save 32 bits of storage. Also, some of the stdlib packages (like strconv) deal exclusively with int64 rather than int32. This has meant changes to my code I didn't expect purely to handle int32 things.

What is your opinion (and perhaps the general consensus) on using int32 purely for efficiency purposes? Is it just worth using an int64 for simplicity?

🌐
Google Groups
groups.google.com › g › golang-nuts › c › AQS9oYoTk_w
Why was int chosen to be 32 bits on x86-64?
May 25, 2011 - Getting rid of int can't be done without using one of the fixed int sizes for slice indexes, lengths, and capacities, always a consistent one so Go programs can be portable. This would either permanently tie us to int32, which is not acceptable, or require using int64 for all indexing, lengths, and capacities, and doing all arithmetic involving them using int64.
🌐
Go Tutorial
golangbot.com › types
Basic Data Types in Go | golangbot.com
May 5, 2024 - In the above program a is of type int and the type of b is inferred from the value assigned to it (95). As we have stated above, the size of int is 32 bit in 32 bit systems and 64 bit in 64 bit systems.
🌐
Google Groups
groups.google.com › g › golang-nuts › c › 7yGYsdFTkWk
Convert int to int32 or int64
This should do it: myInt := (int)myInt64 Look at the topic conversions in the language spec. Note that this conversion will truncate the value if it doesn't fit into the int. On Sat, Apr 18, 2015 at 9:08 AM Brad Fitzpatrick <brad...@golang.org> wrote:
🌐
GeeksforGeeks
geeksforgeeks.org › go language › data-types-in-go
Data Types in Go - GeeksforGeeks
Data types specify the type of data that a valid Go variable can hold. In Go language, the type is divided into four categories which are as follows:
Published   July 11, 2025
🌐
Vintage Story
mods.vintagestory.at › imgui
ImGui - Vintage Story Mod DB
November 30, 2023 - El sistema no puede encontrar el archivo especificado. at System.ModuleHandle.ResolveType(QCallModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type) at System.ModuleHandle.ResolveTypeHandle(Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext) at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[]
🌐
Wikipedia
en.wikipedia.org › wiki › Endianness
Endianness - Wikipedia
3 weeks ago - Positional number systems (mostly base 2, or less often base 10) are the predominant way of representing and particularly of manipulating integer data by computers. In pure form, this is valid for moderately sized non-negative integers, e.g., of C data type unsigned.
🌐
C# Corner
c-sharpcorner.com › interview-question › what-is-the-difference-between-int-and-int
What is the difference between int and int32?
System is a base class for int32.int i=10;from the above instead of "int" i can write "system.int32" where system is a pre defined class.
🌐
Codekru
codekru.com › home › golang data types
Golang Data Types - Codekru
November 6, 2022 - Value of i: -1233 Value of j: 512 Type of i: int16 Type of j: uint16 Size of i in bytes: 2 Size of j in bytes: 2 · Their size is 32 bits or 4 bytes. Range of int32 – The range of int32 is -231 to 231-1
🌐
W3Schools
w3schools.com › c › c_type_conversion.php
C Data Type Conversion
For example, if you try to divide two integers, 5 by 2, you would expect the result to be 2.5.