package main

import (
    "encoding/binary"
    "fmt"
)

func main() {
    u8 := []uint8{0, 1, 2, 3}
    u32LE := binary.LittleEndian.Uint32(u8)
    fmt.Println("little-endian:", u8, "to", u32LE)
    u32BE := binary.BigEndian.Uint32(u8)
    fmt.Println("big-endian:   ", u8, "to", u32BE)
}

Output:

little-endian: [0 1 2 3] to 50462976
big-endian:    [0 1 2 3] to 66051

The Go binary package functions are implemented as a series of shifts.

func (littleEndian) Uint32(b []byte) uint32 {
    return uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24
}

func (bigEndian) Uint32(b []byte) uint32 {
    return uint32(b[3]) | uint32(b[2])<<8 | uint32(b[1])<<16 | uint32(b[0])<<24
}
Answer from peterSO on Stack Overflow
🌐
Socket Loop
socketloop.com › tutorials › golang-how-do-i-convert-int-to-uint8
Golang : How do I convert int to uint8? - SocketLoop
June 15, 2015 - Type cast the variable to uint8 with uint8() function. package main import ( "fmt" "reflect" ) var test int = 8 func main() { fmt.Printf("The value of test is %d \n", test) fmt.Printf("The type of test is %v \n", reflect.TypeOf(test)) newTest ...
Discussions

type conversion - How to convert [4]uint8 into uint32 in Go? - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Ask questions, find answers and collaborate at work with Stack Overflow for Teams More on stackoverflow.com
🌐 stackoverflow.com
August 6, 2016
go - How to convert uint8 to string - Stack Overflow
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... I want to convert uint8 to string but can't figure out how. More on stackoverflow.com
🌐 stackoverflow.com
type conversion - How to convert int[] to uint8[] - Stack Overflow
Golang is a freshly baked language so it’s quite hard to find answers quick for a newcomers like me. ... The predeclared Go int type size is implementation-specific, either 32 or 64 bits (Numeric types). Here's an example of converting big-endian ints to bytes (uint8s). More on stackoverflow.com
🌐 stackoverflow.com
Convert Uint64 to slice []Uint8
Hi all I’m using package satori/uuid to get uuid values But in my case after getting new uuid i need convert it to simple int type I found some solution but can’t understand how after work with int value reconvert it … More on forum.golangbridge.org
🌐 forum.golangbridge.org
0
0
June 13, 2018
🌐
Go Packages
pkg.go.dev › github.com › reiver › go-cast
cast package - github.com/reiver/go-cast - Go Packages
August 10, 2025 - For an example, let's look at converting to an int64. You can safely convert a uint8, uint16, uint32, plus an int, int8, int16, int32, int64, into an int64 without information loss.
🌐
GitHub
github.com › Eun › go-convert › blob › master › uint8.go
go-convert/uint8.go at master · Eun/go-convert
func (s stdRecipes) baseStructToUint8(_ Converter, in reflect.Value, out *uint8) error { if !in.CanInterface() { return errors.New("unable to make interface") } · // check for struct.Uint8() if i, ok := in.Interface().(toUint8); ok { *out = i.Uint8() return nil ·
Author   Eun
🌐
Medium
medium.com › a-journey-with-go › go-cast-vs-conversion-by-example-26e0ef3003f0
Go: Cast vs Conversion by Example | by Vincent | A Journey With Go | Medium
September 12, 2019 - var a int16 = 511fmt.Printf("cast int8: %d\n", int8(a)) fmt.Printf("cast uint8: %d\n", uint8(a)) fmt.Printf("cast int32: %d\n", int32(a))-------------- cast int8: -1 cast uint8: 255 cast int32: 511 · source: https://play.golang.org/p/u9F9KYhiEtU · The bits conversion from the int16 to int8 is the following: 6.4K followers ·
Find elsewhere
🌐
Educative
educative.io › answers › what-is-type-uint8-in-golang
What is type uint8 in Golang?
type uint8 in Golang is the set of all unsigned 8-bit integers. The set ranges from 0 to 255. You should use type uint8 when you strictly want a positive integer in the range 0-255.
🌐
Go Forum
forum.golangbridge.org › getting help
Convert Uint64 to slice []Uint8 - Getting Help - Go Forum
June 13, 2018 - Hi all I’m using package satori/uuid to get uuid values But in my case after getting new uuid i need convert it to simple int type I found some solution but can’t understand how after work with int value reconvert it …
🌐
YourBasic
yourbasic.org › golang › convert-int-to-string
Convert between int, int64 and string · YourBasic Go
CODE EXAMPLE Use strconv.Itoa to convert an int to a decimal string, and strconv.Atoi to parse a string to an int.
🌐
Educative
educative.io › answers › what-is-type-int8-in-golang
What is type int8 in Golang?
These variables can hold all different data types, whether they are numbers, words, or any other type. To restrict the type of data stored inside these variables, we need to specify the data type of the variables. int is one of the available numeric data types in Go used to store signed integers.
🌐
DEV Community
dev.to › melvin2016 › how-to-convert-an-int-type-value-to-a-uint-type-value-in-go-or-golang-531a
How to convert an int type value to a uint type value in Go or Golang? - DEV Community
August 18, 2022 - To convert an int type value to a uint type value in Go or Golang, you can use the built-in uint() function and pass the int type value as an argument to the function.
🌐
GoLinuxCloud
golinuxcloud.com › home › golang solutions › golang string to uint8 type casting [solved]
Golang string to uint8 type casting [SOLVED] | GoLinuxCloud
December 25, 2022 - So you have to check for errors to make sure its the correct value you need. This is what you need for converting from string to integer like if you read balance or price from Stripe API, or others. If you look for greater flexibly, Golang offers the ParseInt method which has a function signature accepting both, base and bitsize.
🌐
gosamples
gosamples.dev › tutorials › convert int to string in go
🔢 Convert int to string in Go
July 23, 2021 - Use strconv.FormatInt function to convert an integer variable to a string in Go.
🌐
GitHub
github.com › brianvoe › gofakeit › blob › master › number.go
gofakeit/number.go at master · brianvoe/gofakeit
Display: "Uint8", Category: "number", Description: "Unsigned 8-bit integer, range 0–255", Example: "152", Output: "uint8", Aliases: []string{ "byte-sized unsigned", "octet quantity", "small-range unsigned", "one-byte value", "0-255 whole", }, Keywords: []string{ "unsigned", "8bit", "byte", "octet", "range", "integer", }, Generate: func(f *Faker, m *MapParams, info *Info) (any, error) { return uint8Func(f), nil }, }) ·
Author   brianvoe
🌐
Melvin George
melvingeorge.me › blog › convert-int-type-value-to-uint-type-value-go-golang
How to convert an int type value to a uint type value in Go or Golang? | MELVIN GEORGE
August 18, 2022 - To convert an int type value to a uint type value in Go or Golang, you can use the built-in uint() function and pass the int type value as an argument to the function.
🌐
Reddit
reddit.com › r/golang › a question about converting rune to uint8
r/golang on Reddit: a question about converting rune to uint8
November 14, 2021 -

uint8(rune(someRune))

In this code, can any problem be occurred?

because rune is alias type of int32.

rune type's range is larger than uint8.

so I think when converting rune to uint8, something wrong might be happened.