Try it Live
Run Uint examples in the interactive playground
Uint8
A branded type for 8-bit unsigned integers (range: 0-255) represented as JavaScript numbers with compile-time type safety.Overview
Uint8Type provides type-safe operations on 8-bit unsigned integers with:
- Compile-time type branding for type safety
- Runtime validation and overflow/underflow checking
- Zero runtime overhead (just a number internally)
- Full arithmetic, bitwise, and comparison operations
Type Definition
Range
- Minimum: 0
- Maximum: 255
- Size: 8 bits
Constants
Construction
from
Create from number or string:fromNumber
Create from number:fromBigint
Create from bigint:fromHex
Create from hex string:fromBytes
Create from Uint8Array (1 byte):Conversion
toNumber
toBigint
toHex
toBytes
toString
Arithmetic
All arithmetic operations validate that results stay within valid range.plus
minus
times
dividedBy
modulo
Comparison
equals
lessThan
greaterThan
isZero
minimum
maximum
Bitwise Operations
bitwiseAnd
bitwiseOr
bitwiseXor
bitwiseNot
shiftLeft
shiftRight
Bit Analysis
bitLength
Get number of bits needed to represent value:leadingZeros
Count leading zero bits:popCount
Count set bits:Validation
isValid
Use Cases
- Protocol buffers and binary formats
- Network packet headers
- Byte-level data manipulation
- Image pixel values (RGB components)
- Hardware register values
- Compact data structures
- Checksum and hash algorithms
Error Handling
All operations throw on invalid inputs:- Non-integer values
- Negative values
- Values exceeding 255
- Arithmetic overflow/underflow
- Division by zero

