Home »
Golang »
Golang Reference
Golang math.MaxUint8 Constant with Examples
Golang | math.MaxUint8 Constant: Here, we are going to learn about the MaxUint8 constant of the math package with its usages, syntax, and examples.
Submitted by IncludeHelp, on August 28, 2021
math.MaxUint8 Constant
The MaxUint8 constant is an inbuilt constant of the math package which is used to get the highest (maximum) value that can be represented by a uint8 (unsigned int8).
The value of math.MaxUint8 constants is 1<<8 - 1 or 255.
Syntax
int math.MaxUint8
Parameters
Return Value
The return type of math.MaxUint8 constant is int, it returns the highest (maximum) value that can be represented by a uint8.
Example 1
// Golang program to demonstrate the
// example of math.MaxUint8 Constant
package main
import (
"fmt"
"math"
)
func main() {
fmt.Printf("Type of math.MaxUint8 is %T\n", math.MaxUint8)
fmt.Println("Value of math.MaxUint8:", math.MaxUint8)
}
Output:
Type of math.MaxUint8 is int
Value of math.MaxUint8: 255
Explanation:
In the above program, we imported the math package to use the math.MaxUint8 constant, then printed the type and value of the math.MaxUint8 constant.
Example 2
// Golang program to demonstrate the
// example of math.MaxUint8 Constant
package main
import (
"fmt"
"math"
)
// creating function to
// return the value of MaxUint8.
func getMaxUint8() int {
return math.MaxUint8
}
func main() {
fmt.Println("Value of math.MaxUint8:", getMaxUint8())
}
Output:
Value of math.MaxUint8: 255
Golang math Package Constants and Functions »