The first value returned by range is the index, not the value. What you need is:

func main() {
    one := uint(1)
    ones := []uint{1, 1, 1}
    for _, x := range ones {
        if x != one {
            print("ERR")
        }
    }
}
Answer from Ainar-G on Stack Overflow
🌐
GitHub
github.com › golang › go › issues › 66967
spec: a valid range uint(maxUint) is not accepted · Issue #66967 · golang/go
April 22, 2024 - The range expression uint(maxUint) is an integer expression but cannot be assigned to an int variable, yet this code is permitted. Or perhaps the intent was that the assignability requirement to int is only present if the expression x is untyped, ...
Author   griesemer
🌐
Ado
ado.xyz › blog › go-numerical-type-ranges
Go Numerical Type Ranges - Ado.xyz
May 9, 2020 - Again, similar to the default int variable for 32-bit systems, the ranges you can represent is between -9,223,372,036,854,775,808 and 9,223,372,036,854,775,807. Much like int, the uint type has a range that is dependent on the underlying ...
🌐
Rotational
rotational.io › blog › ranges-of-integer-data-types
Rotational Labs | Ranges of Integer Data Types
So without further ado, here are ... = 1<<63 - 1 MinInt64 int64 = -1 << 63 MaxUint8 uint8 = 1<<8 - 1 MaxUint16 uint16 = 1<<16 - 1 MaxUint32 uint32 = 1<<32 - 1 MaxUint64 uint64 = 1<<64 - 1 ) // Complement method (system specific) ...
🌐
Go Tutorial
golangbot.com › types
Basic Data Types in Go | golangbot.com
May 5, 2024 - Please read Golang tutorial part 3: Variables of this series to learn about variables. The following are the basic data types available in Go · bool · Numeric Types · int8, int16, int32, int64, int · uint8, uint16, uint32, uint64, uint · ...
🌐
Go Packages
pkg.go.dev › builtin
builtin package - builtin - Go Packages
Range: -9223372036854775808 through 9223372036854775807. ... rune is an alias for int32 and is equivalent to int32 in all ways. It is used, by convention, to distinguish character values from integer values. ... string is the set of all strings of 8-bit bytes, conventionally but not necessarily ...
🌐
Golang Docs
golangdocs.com › home › integers in golang
Integers in Golang - Golang Docs
December 24, 2019 - uint16 (16-bit unsigned integer whose range is 0 to 65535 )
Find elsewhere
🌐
ZetCode
zetcode.com › golang › builtins-uint-type
Understanding the uint Type in Golang
May 8, 2025 - The uint type represents unsigned integers in Go. Unlike signed integers, uint values are always positive. They provide a larger positive range than their signed counterparts at the same bit size.
🌐
DigitalOcean
digitalocean.com › community › tutorials › understanding-data-types-in-go
Understanding Data Types in Go | DigitalOcean
May 1, 2019 - Because an int type needs to support both positive and negative values, an 8-bit integer (int8) will have a range of -128 to 127, for a total of 256 unique possible values. Go has the following architecture-independent integer types: uint8 unsigned 8-bit integers (0 to 255) uint16 unsigned ...
🌐
Medium
medium.com › @vipin.raj_16576 › understanding-uint32-vs-uint-in-go-a-guide-to-choosing-the-right-integer-type-5e6c22205ccb
Understanding uint32 vs. uint in Go: A Guide to Choosing the Right Integer Type | by Vipin Raj | Medium
October 8, 2024 - ... TypeSize on 32-bit SystemSize on 64-bit SystemRange (32-bit)Range (64-bit)uint32 bits64 bits0 to 4,294,967,2950 to 18,446,744,073,709,551,615uint3232 bits32 bits0 to 4,294,967,295Same (0 to 4,294,967,295 on all)
🌐
LabEx
labex.io › tutorials › go-numerical-types-in-golang-149067
Numerical Types in Golang | LabEx
They are both 8-bit integers and can represent 256 values. In the unsigned integer type uint8, the range it can represent is from 0 to 255, while in the signed integer type int8, the range it can represent is from -128 to 127.
🌐
Reddit
reddit.com › r/golang › weird type conversion (uint8 to i32) using range function ?
r/golang on Reddit: Weird type conversion (uint8 to i32) using range function ?
December 21, 2023 -

Hello gophers!

I encountered a weird conversion when iterating over strings.
I used "résumé" as string following a youtube video.

So what happend was, that it seems that go converted uint8 to int32 when using the range function.

And I am unsure why it did that, because u8 should be enough no ?
Also when checking what values the runes resemble I did get a different value for 'é' back ?
Maybe someone can clear this up for me, thanks in advance.

func main() {
var myString = "résumé"

var indexed = myString[0]
fmt.Printf("%v %T\n", indexed, indexed)

indexed = myString[1]
fmt.Printf("%v %T\n", indexed, indexed)

}

Output:
Value: 114, Type: uint8
Value: 195, Type: uint8 // <- This value seems to be wrong !

And then using range it changed type to int32 for some reason ?
Can someone explain why that is ?

func main() {
/* ... */

// range does encode it to int32 ?
for index, value := range myString {
    fmt.Printf("Index: %v, Value: %v, Type: %T\n", index, value, value)
}

}

Output:
Index: 0, Value: 114, Type: int32
Index: 1, Value: 233, Type: int32
Index: 3, Value: 115, Type: int32
Index: 4, Value: 117, Type: int32
Index: 5, Value: 109, Type: int32
Index: 6, Value: 233, Type: int32

Then checking backwards what runes i get from uint8 using the int32 values i get the correct ones with 233 weirdly enough.
Any ideas why i get "wrong" value of 'e' from uint8 in the first place ?

func main() {
/* ... */

var rune_195 = string(uint8(195))
fmt.Println(rune_195)
var rune_233 = string(uint8(233))
fmt.Println(rune_233)

}

Output:
Ã
é

🌐
CalliCoder
callicoder.com › golang-basic-types-operators-type-conversion
Golang Basic Types, Operators and Type Conversion | CalliCoder
February 18, 2022 - It is 32 bits wide on a 32-bit system and 64-bits wide on a 64-bit system. When you are working with integer values, you should always use the int data type unless you have a good reason to use the sized or unsigned integer types.
🌐
Boot.dev
blog.boot.dev › golang › default-native-types-golang
Don't Go to Casting Hell - Use Default Native Types in Go | Boot.dev
May 21, 2020 - In all of the above cases, the choice of specific sub-types are based on range and precision. int8 can store values between -128 and 127, while int64 ranges from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
🌐
Go
go.dev › src › builtin › builtin.go
- The Go Programming Language
26 type uint8 uint8 27 28 // uint16 is the set of all unsigned 16-bit integers. 29 // Range: 0 through 65535. 30 type uint16 uint16 31 32 // uint32 is the set of all unsigned 32-bit integers. 33 // Range: 0 through 4294967295. 34 type uint32 uint32 35 36 // uint64 is the set of all unsigned ...
🌐
Golang By Example
golangbyexample.com › home
Rusticcutscb | สล็อตเว็บตรง RTP สูง เว็บตรงสล็อต แตกหนัก รับวอเลท
October 19, 2025 - สล็อตเว็บตรง rusticcutscb.com RTP สูง สล็อต แตกหนักทุกค่ายดัง เว็บตรงสล็อต รองรับทรูวอเลทเต็มระบบ ไม่มีขั้นต่ำ เว็บส...