Skip to main content
@tevm/voltaire
@tevm/voltaire / primitives/Uint8

primitives/Uint8

Variables

MAX

const MAX: Uint8Type
Defined in: src/primitives/Uint8/constants.js:12

MIN

const MIN: Uint8Type
Defined in: src/primitives/Uint8/constants.js:9

ONE

const ONE: Uint8Type
Defined in: src/primitives/Uint8/constants.js:18

SIZE

const SIZE: number = 8
Defined in: src/primitives/Uint8/constants.js:21

Uint8Type

const Uint8Type: object
Defined in: src/primitives/Uint8/index.ts:72

Type Declaration

bitLength()
bitLength: (uint) => number
Get bit length of Uint8 value (position of highest set bit)
Parameters
uint
Uint8Type Input value
Returns
number Number of bits needed to represent value (0-8)
See
https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation
Since
0.0.0
Throws
Example
import * as Uint8 from './primitives/Uint8/index.js';
Uint8.bitLength(Uint8.from(0)); // 0
Uint8.bitLength(Uint8.from(1)); // 1
Uint8.bitLength(Uint8.from(255)); // 8
Uint8.bitLength(Uint8.from(128)); // 8
bitwiseAnd()
bitwiseAnd: (a, b) => Uint8Type
Bitwise AND of two Uint8 values
Parameters
a
Uint8Type First operand
b
Uint8Type Second operand
Returns
Uint8Type Bitwise AND result
See
https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation
Since
0.0.0
Throws
Example
import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(0b11110000);
const b = Uint8.from(0b11001100);
const result = Uint8.bitwiseAnd(a, b); // 0b11000000 = 192
bitwiseNot()
bitwiseNot: (uint) => Uint8Type
Bitwise NOT of Uint8 value
Parameters
uint
Uint8Type Input value
Returns
Uint8Type Bitwise NOT result
See
https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation
Since
0.0.0
Throws
Example
import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(0b11110000);
const result = Uint8.bitwiseNot(a); // 0b00001111 = 15
bitwiseOr()
bitwiseOr: (a, b) => Uint8Type
Bitwise OR of two Uint8 values
Parameters
a
Uint8Type First operand
b
Uint8Type Second operand
Returns
Uint8Type Bitwise OR result
See
https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation
Since
0.0.0
Throws
Example
import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(0b11110000);
const b = Uint8.from(0b00001111);
const result = Uint8.bitwiseOr(a, b); // 0b11111111 = 255
bitwiseXor()
bitwiseXor: (a, b) => Uint8Type
Bitwise XOR of two Uint8 values
Parameters
a
Uint8Type First operand
b
Uint8Type Second operand
Returns
Uint8Type Bitwise XOR result
See
https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation
Since
0.0.0
Throws
Example
import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(0b11110000);
const b = Uint8.from(0b11001100);
const result = Uint8.bitwiseXor(a, b); // 0b00111100 = 60
dividedBy()
dividedBy: (a, b) => Uint8Type
Divide two Uint8 values (integer division)
Parameters
a
Uint8Type Dividend
b
Uint8Type Divisor
Returns
Uint8Type Quotient (floor(a / b))
See
https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation
Since
0.0.0
Throws
If divisor is zero
Example
import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(100);
const b = Uint8.from(5);
const quotient = Uint8.dividedBy(a, b); // 20
equals()
equals: (a, b) => boolean
Check if two Uint8 values are equal
Parameters
a
Uint8Type First operand
b
Uint8Type Second operand
Returns
boolean true if a === b
See
https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation
Since
0.0.0
Throws
Example
import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(100);
const b = Uint8.from(100);
const isEqual = Uint8.equals(a, b); // true
from()
from: (value) => Uint8Type
Create Uint8 from number or string
Parameters
value
number or decimal/hex string string | number
Returns
Uint8Type Uint8 value
See
https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation
Since
0.0.0
Throws
If value is not a valid integer
Throws
If value is negative
Throws
If value exceeds 255
Example
import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(100);
const b = Uint8.from("255");
const c = Uint8.from("0xff");
fromBigint()
fromBigint: (value) => Uint8Type
Create Uint8 from bigint
Parameters
value
bigint bigint value
Returns
Uint8Type Uint8 value
See
https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation
Since
0.0.0
Throws
If value is out of range
Example
import * as Uint8 from './primitives/Uint8/index.js';
const value = Uint8.fromBigint(255n);
fromBytes()
fromBytes: (bytes) => Uint8Type
Create Uint8 from Uint8Array (single byte)
Parameters
bytes
Uint8Array<ArrayBufferLike> Uint8Array (must be exactly 1 byte)
Returns
Uint8Type Uint8 value
See
https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation
Since
0.0.0
Throws
If bytes length is not 1
Example
import * as Uint8 from './primitives/Uint8/index.js';
const bytes = new Uint8Array([255]);
const value = Uint8.fromBytes(bytes);
fromHex()
fromHex: (hex) => Uint8Type
Create Uint8 from hex string
Parameters
hex
string hex string (with or without 0x prefix)
Returns
Uint8Type Uint8 value
See
https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation
Since
0.0.0
Throws
If hex is invalid or out of range
Example
import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.fromHex("0xff");
const b = Uint8.fromHex("ff");
fromNumber()
fromNumber: (value) => Uint8Type
Create Uint8 from number
Parameters
value
number number value
Returns
Uint8Type Uint8 value
See
https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation
Since
0.0.0
Throws
If value is out of range or not an integer
Example
import * as Uint8 from './primitives/Uint8/index.js';
const value = Uint8.fromNumber(255);
greaterThan()
greaterThan: (a, b) => boolean
Check if first Uint8 is greater than second
Parameters
a
Uint8Type First operand
b
Uint8Type Second operand
Returns
boolean true if a > b
See
https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation
Since
0.0.0
Throws
Example
import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(100);
const b = Uint8.from(50);
const isGreater = Uint8.greaterThan(a, b); // true
isValid()
isValid: (value) => value is Uint8Type
Check if value is a valid Uint8
Parameters
value
unknown Value to check
Returns
value is Uint8Type true if valid Uint8
See
https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation
Since
0.0.0
Throws
Example
import * as Uint8 from './primitives/Uint8/index.js';
Uint8.isValid(100); // true
Uint8.isValid(255); // true
Uint8.isValid(256); // false
Uint8.isValid(-1); // false
Uint8.isValid(1.5); // false
isZero()
isZero: (uint) => boolean
Check if Uint8 value is zero
Parameters
uint
Uint8Type Uint8 value
Returns
boolean true if uint === 0
See
https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation
Since
0.0.0
Throws
Example
import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(0);
const b = Uint8.from(100);
Uint8.isZero(a); // true
Uint8.isZero(b); // false
leadingZeros()
leadingZeros: (uint) => number
Count leading zero bits in Uint8 value
Parameters
uint
Uint8Type Input value
Returns
number Number of leading zero bits (0-8)
See
https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation
Since
0.0.0
Throws
Example
import * as Uint8 from './primitives/Uint8/index.js';
Uint8.leadingZeros(Uint8.from(0)); // 8
Uint8.leadingZeros(Uint8.from(1)); // 7
Uint8.leadingZeros(Uint8.from(255)); // 0
Uint8.leadingZeros(Uint8.from(128)); // 0
lessThan()
lessThan: (a, b) => boolean
Check if first Uint8 is less than second
Parameters
a
Uint8Type First operand
b
Uint8Type Second operand
Returns
boolean true if a < b
See
https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation
Since
0.0.0
Throws
Example
import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(50);
const b = Uint8.from(100);
const isLess = Uint8.lessThan(a, b); // true
MAX
MAX: Uint8Type
maximum()
maximum: (a, b) => Uint8Type
Return maximum of two Uint8 values
Parameters
a
Uint8Type First operand
b
Uint8Type Second operand
Returns
Uint8Type Maximum value
See
https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation
Since
0.0.0
Throws
Example
import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(100);
const b = Uint8.from(50);
const max = Uint8.maximum(a, b); // 100
MIN
MIN: Uint8Type
minimum()
minimum: (a, b) => Uint8Type
Return minimum of two Uint8 values
Parameters
a
Uint8Type First operand
b
Uint8Type Second operand
Returns
Uint8Type Minimum value
See
https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation
Since
0.0.0
Throws
Example
import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(100);
const b = Uint8.from(50);
const min = Uint8.minimum(a, b); // 50
minus()
minus: (a, b) => Uint8Type
Subtract two Uint8 values with underflow checking
Parameters
a
Uint8Type First operand
b
Uint8Type Second operand
Returns
Uint8Type Difference (a - b)
See
https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation
Since
0.0.0
Throws
If result is negative
Example
import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(100);
const b = Uint8.from(50);
const diff = Uint8.minus(a, b); // 50
modulo()
modulo: (a, b) => Uint8Type
Compute modulo of two Uint8 values
Parameters
a
Uint8Type Dividend
b
Uint8Type Divisor
Returns
Uint8Type Remainder (a % b)
See
https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation
Since
0.0.0
Throws
If divisor is zero
Example
import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(100);
const b = Uint8.from(7);
const remainder = Uint8.modulo(a, b); // 2
ONE
ONE: Uint8Type
plus()
plus: (a, b) => Uint8Type
Add two Uint8 values with overflow checking
Parameters
a
Uint8Type First operand
b
Uint8Type Second operand
Returns
Uint8Type Sum (a + b)
See
https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation
Since
0.0.0
Throws
If result exceeds maximum value
Example
import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(100);
const b = Uint8.from(50);
const sum = Uint8.plus(a, b); // 150
popCount()
popCount: (uint) => number
Count number of set bits (population count) in Uint8 value
Parameters
uint
Uint8Type Input value
Returns
number Number of set bits (0-8)
See
https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation
Since
0.0.0
Throws
Example
import * as Uint8 from './primitives/Uint8/index.js';
Uint8.popCount(Uint8.from(0)); // 0
Uint8.popCount(Uint8.from(255)); // 8
Uint8.popCount(Uint8.from(0b10101010)); // 4
shiftLeft()
shiftLeft: (uint, shift) => Uint8Type
Left shift Uint8 value
Parameters
uint
Uint8Type Value to shift
shift
number Number of bits to shift (0-7)
Returns
Uint8Type Left-shifted value (masked to 8 bits)
See
https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation
Since
0.0.0
Throws
Example
import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(0b00001111);
const result = Uint8.shiftLeft(a, 4); // 0b11110000 = 240
shiftRight()
shiftRight: (uint, shift) => Uint8Type
Right shift Uint8 value (logical shift)
Parameters
uint
Uint8Type Value to shift
shift
number Number of bits to shift (0-7)
Returns
Uint8Type Right-shifted value
See
https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation
Since
0.0.0
Throws
Example
import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(0b11110000);
const result = Uint8.shiftRight(a, 4); // 0b00001111 = 15
SIZE
SIZE: number
times()
times: (a, b) => Uint8Type
Multiply two Uint8 values with overflow checking
Parameters
a
Uint8Type First operand
b
Uint8Type Second operand
Returns
Uint8Type Product (a * b)
See
https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation
Since
0.0.0
Throws
If result exceeds maximum value
Example
import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(10);
const b = Uint8.from(5);
const product = Uint8.times(a, b); // 50
toBigint()
toBigint: (uint) => bigint
Convert Uint8 to bigint
Parameters
uint
Uint8Type Uint8 value
Returns
bigint bigint value
See
https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation
Since
0.0.0
Throws
Example
import * as Uint8 from './primitives/Uint8/index.js';
const value = Uint8.from(255);
const bigintValue = Uint8.toBigint(value); // 255n
toBytes()
toBytes: (uint) => Uint8Array<ArrayBufferLike>
Convert Uint8 to Uint8Array (1 byte)
Parameters
uint
Uint8Type Uint8 value
Returns
Uint8Array<ArrayBufferLike> Uint8Array of length 1
See
https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation
Since
0.0.0
Throws
Example
import * as Uint8 from './primitives/Uint8/index.js';
const value = Uint8.from(255);
const bytes = Uint8.toBytes(value); // Uint8Array([255])
toHex()
toHex: (uint, padded?) => string
Convert Uint8 to hex string
Parameters
uint
Uint8Type Uint8 value
padded?
boolean = true Whether to pad to 2 characters (1 byte)
Returns
string Hex string with 0x prefix
See
https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation
Since
0.0.0
Throws
Example
import * as Uint8 from './primitives/Uint8/index.js';
const value = Uint8.from(255);
const hex1 = Uint8.toHex(value); // "0xff"
const hex2 = Uint8.toHex(value, false); // "0xff"
const value2 = Uint8.from(15);
const hex3 = Uint8.toHex(value2); // "0x0f"
const hex4 = Uint8.toHex(value2, false); // "0xf"
toNumber()
toNumber: (uint) => number
Convert Uint8 to number
Parameters
uint
Uint8Type Uint8 value
Returns
number number value
See
https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation
Since
0.0.0
Throws
Example
import * as Uint8 from './primitives/Uint8/index.js';
const value = Uint8.from(255);
const num = Uint8.toNumber(value); // 255
toString()
toString: (uint) => string
Convert Uint8 to decimal string
Parameters
uint
Uint8Type Uint8 value
Returns
string Decimal string representation
See
https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation
Since
0.0.0
Throws
Example
import * as Uint8 from './primitives/Uint8/index.js';
const value = Uint8.from(255);
const str = Uint8.toString(value); // "255"
ZERO
ZERO: Uint8Type

ZERO

const ZERO: Uint8Type
Defined in: src/primitives/Uint8/constants.js:15

Functions

bitLength()

bitLength(uint): number
Defined in: src/primitives/Uint8/bitLength.js:18 Get bit length of Uint8 value (position of highest set bit)

Parameters

uint
Uint8Type Input value

Returns

number Number of bits needed to represent value (0-8)

See

https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation

Since

0.0.0

Throws

Example

import * as Uint8 from './primitives/Uint8/index.js';
Uint8.bitLength(Uint8.from(0)); // 0
Uint8.bitLength(Uint8.from(1)); // 1
Uint8.bitLength(Uint8.from(255)); // 8
Uint8.bitLength(Uint8.from(128)); // 8

bitwiseAnd()

bitwiseAnd(a, b): Uint8Type
Defined in: src/primitives/Uint8/bitwiseAnd.js:18 Bitwise AND of two Uint8 values

Parameters

a
Uint8Type First operand
b
Uint8Type Second operand

Returns

Uint8Type Bitwise AND result

See

https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation

Since

0.0.0

Throws

Example

import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(0b11110000);
const b = Uint8.from(0b11001100);
const result = Uint8.bitwiseAnd(a, b); // 0b11000000 = 192

bitwiseNot()

bitwiseNot(uint): Uint8Type
Defined in: src/primitives/Uint8/bitwiseNot.js:18 Bitwise NOT of Uint8 value

Parameters

uint
Uint8Type Input value

Returns

Uint8Type Bitwise NOT result

See

https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation

Since

0.0.0

Throws

Example

import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(0b11110000);
const result = Uint8.bitwiseNot(a); // 0b00001111 = 15

bitwiseOr()

bitwiseOr(a, b): Uint8Type
Defined in: src/primitives/Uint8/bitwiseOr.js:18 Bitwise OR of two Uint8 values

Parameters

a
Uint8Type First operand
b
Uint8Type Second operand

Returns

Uint8Type Bitwise OR result

See

https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation

Since

0.0.0

Throws

Example

import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(0b11110000);
const b = Uint8.from(0b00001111);
const result = Uint8.bitwiseOr(a, b); // 0b11111111 = 255

bitwiseXor()

bitwiseXor(a, b): Uint8Type
Defined in: src/primitives/Uint8/bitwiseXor.js:18 Bitwise XOR of two Uint8 values

Parameters

a
Uint8Type First operand
b
Uint8Type Second operand

Returns

Uint8Type Bitwise XOR result

See

https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation

Since

0.0.0

Throws

Example

import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(0b11110000);
const b = Uint8.from(0b11001100);
const result = Uint8.bitwiseXor(a, b); // 0b00111100 = 60

dividedBy()

dividedBy(a, b): Uint8Type
Defined in: src/primitives/Uint8/dividedBy.js:18 Divide two Uint8 values (integer division)

Parameters

a
Uint8Type Dividend
b
Uint8Type Divisor

Returns

Uint8Type Quotient (floor(a / b))

See

https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation

Since

0.0.0

Throws

If divisor is zero

Example

import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(100);
const b = Uint8.from(5);
const quotient = Uint8.dividedBy(a, b); // 20

equals()

equals(a, b): boolean
Defined in: src/primitives/Uint8/equals.js:18 Check if two Uint8 values are equal

Parameters

a
Uint8Type First operand
b
Uint8Type Second operand

Returns

boolean true if a === b

See

https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation

Since

0.0.0

Throws

Example

import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(100);
const b = Uint8.from(100);
const isEqual = Uint8.equals(a, b); // true

from()

from(value): Uint8Type
Defined in: src/primitives/Uint8/from.js:26 Create Uint8 from number or string

Parameters

value
number or decimal/hex string string | number

Returns

Uint8Type Uint8 value

See

https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation

Since

0.0.0

Throws

If value is not a valid integer

Throws

If value is negative

Throws

If value exceeds 255

Example

import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(100);
const b = Uint8.from("255");
const c = Uint8.from("0xff");

fromBigint()

fromBigint(value): Uint8Type
Defined in: src/primitives/Uint8/fromBigint.js:17 Create Uint8 from bigint

Parameters

value
bigint bigint value

Returns

Uint8Type Uint8 value

See

https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation

Since

0.0.0

Throws

If value is out of range

Example

import * as Uint8 from './primitives/Uint8/index.js';
const value = Uint8.fromBigint(255n);

fromBytes()

fromBytes(bytes): Uint8Type
Defined in: src/primitives/Uint8/fromBytes.js:16 Create Uint8 from Uint8Array (single byte)

Parameters

bytes
Uint8Array<ArrayBufferLike> Uint8Array (must be exactly 1 byte)

Returns

Uint8Type Uint8 value

See

https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation

Since

0.0.0

Throws

If bytes length is not 1

Example

import * as Uint8 from './primitives/Uint8/index.js';
const bytes = new Uint8Array([255]);
const value = Uint8.fromBytes(bytes);

fromHex()

fromHex(hex): Uint8Type
Defined in: src/primitives/Uint8/fromHex.js:18 Create Uint8 from hex string

Parameters

hex
string hex string (with or without 0x prefix)

Returns

Uint8Type Uint8 value

See

https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation

Since

0.0.0

Throws

If hex is invalid or out of range

Example

import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.fromHex("0xff");
const b = Uint8.fromHex("ff");

fromNumber()

fromNumber(value): Uint8Type
Defined in: src/primitives/Uint8/fromNumber.js:17 Create Uint8 from number

Parameters

value
number number value

Returns

Uint8Type Uint8 value

See

https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation

Since

0.0.0

Throws

If value is out of range or not an integer

Example

import * as Uint8 from './primitives/Uint8/index.js';
const value = Uint8.fromNumber(255);

greaterThan()

greaterThan(a, b): boolean
Defined in: src/primitives/Uint8/greaterThan.js:18 Check if first Uint8 is greater than second

Parameters

a
Uint8Type First operand
b
Uint8Type Second operand

Returns

boolean true if a > b

See

https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation

Since

0.0.0

Throws

Example

import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(100);
const b = Uint8.from(50);
const isGreater = Uint8.greaterThan(a, b); // true

isValid()

isValid(value): value is Uint8Type
Defined in: src/primitives/Uint8/isValid.js:21 Check if value is a valid Uint8

Parameters

value
unknown Value to check

Returns

value is Uint8Type true if valid Uint8

See

https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation

Since

0.0.0

Throws

Example

import * as Uint8 from './primitives/Uint8/index.js';
Uint8.isValid(100); // true
Uint8.isValid(255); // true
Uint8.isValid(256); // false
Uint8.isValid(-1); // false
Uint8.isValid(1.5); // false

isZero()

isZero(uint): boolean
Defined in: src/primitives/Uint8/isZero.js:18 Check if Uint8 value is zero

Parameters

uint
Uint8Type Uint8 value

Returns

boolean true if uint === 0

See

https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation

Since

0.0.0

Throws

Example

import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(0);
const b = Uint8.from(100);
Uint8.isZero(a); // true
Uint8.isZero(b); // false

leadingZeros()

leadingZeros(uint): number
Defined in: src/primitives/Uint8/leadingZeros.js:18 Count leading zero bits in Uint8 value

Parameters

uint
Uint8Type Input value

Returns

number Number of leading zero bits (0-8)

See

https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation

Since

0.0.0

Throws

Example

import * as Uint8 from './primitives/Uint8/index.js';
Uint8.leadingZeros(Uint8.from(0)); // 8
Uint8.leadingZeros(Uint8.from(1)); // 7
Uint8.leadingZeros(Uint8.from(255)); // 0
Uint8.leadingZeros(Uint8.from(128)); // 0

lessThan()

lessThan(a, b): boolean
Defined in: src/primitives/Uint8/lessThan.js:18 Check if first Uint8 is less than second

Parameters

a
Uint8Type First operand
b
Uint8Type Second operand

Returns

boolean true if a < b

See

https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation

Since

0.0.0

Throws

Example

import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(50);
const b = Uint8.from(100);
const isLess = Uint8.lessThan(a, b); // true

maximum()

maximum(a, b): Uint8Type
Defined in: src/primitives/Uint8/maximum.js:18 Return maximum of two Uint8 values

Parameters

a
Uint8Type First operand
b
Uint8Type Second operand

Returns

Uint8Type Maximum value

See

https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation

Since

0.0.0

Throws

Example

import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(100);
const b = Uint8.from(50);
const max = Uint8.maximum(a, b); // 100

minimum()

minimum(a, b): Uint8Type
Defined in: src/primitives/Uint8/minimum.js:18 Return minimum of two Uint8 values

Parameters

a
Uint8Type First operand
b
Uint8Type Second operand

Returns

Uint8Type Minimum value

See

https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation

Since

0.0.0

Throws

Example

import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(100);
const b = Uint8.from(50);
const min = Uint8.minimum(a, b); // 50

minus()

minus(a, b): Uint8Type
Defined in: src/primitives/Uint8/minus.js:18 Subtract two Uint8 values with underflow checking

Parameters

a
Uint8Type First operand
b
Uint8Type Second operand

Returns

Uint8Type Difference (a - b)

See

https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation

Since

0.0.0

Throws

If result is negative

Example

import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(100);
const b = Uint8.from(50);
const diff = Uint8.minus(a, b); // 50

modulo()

modulo(a, b): Uint8Type
Defined in: src/primitives/Uint8/modulo.js:18 Compute modulo of two Uint8 values

Parameters

a
Uint8Type Dividend
b
Uint8Type Divisor

Returns

Uint8Type Remainder (a % b)

See

https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation

Since

0.0.0

Throws

If divisor is zero

Example

import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(100);
const b = Uint8.from(7);
const remainder = Uint8.modulo(a, b); // 2

plus()

plus(a, b): Uint8Type
Defined in: src/primitives/Uint8/plus.js:20 Add two Uint8 values with overflow checking

Parameters

a
Uint8Type First operand
b
Uint8Type Second operand

Returns

Uint8Type Sum (a + b)

See

https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation

Since

0.0.0

Throws

If result exceeds maximum value

Example

import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(100);
const b = Uint8.from(50);
const sum = Uint8.plus(a, b); // 150

popCount()

popCount(uint): number
Defined in: src/primitives/Uint8/popCount.js:17 Count number of set bits (population count) in Uint8 value

Parameters

uint
Uint8Type Input value

Returns

number Number of set bits (0-8)

See

https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation

Since

0.0.0

Throws

Example

import * as Uint8 from './primitives/Uint8/index.js';
Uint8.popCount(Uint8.from(0)); // 0
Uint8.popCount(Uint8.from(255)); // 8
Uint8.popCount(Uint8.from(0b10101010)); // 4

shiftLeft()

shiftLeft(uint, shift): Uint8Type
Defined in: src/primitives/Uint8/shiftLeft.js:19 Left shift Uint8 value

Parameters

uint
Uint8Type Value to shift
shift
number Number of bits to shift (0-7)

Returns

Uint8Type Left-shifted value (masked to 8 bits)

See

https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation

Since

0.0.0

Throws

Example

import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(0b00001111);
const result = Uint8.shiftLeft(a, 4); // 0b11110000 = 240

shiftRight()

shiftRight(uint, shift): Uint8Type
Defined in: src/primitives/Uint8/shiftRight.js:17 Right shift Uint8 value (logical shift)

Parameters

uint
Uint8Type Value to shift
shift
number Number of bits to shift (0-7)

Returns

Uint8Type Right-shifted value

See

https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation

Since

0.0.0

Throws

Example

import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(0b11110000);
const result = Uint8.shiftRight(a, 4); // 0b00001111 = 15

times()

times(a, b): Uint8Type
Defined in: src/primitives/Uint8/times.js:20 Multiply two Uint8 values with overflow checking

Parameters

a
Uint8Type First operand
b
Uint8Type Second operand

Returns

Uint8Type Product (a * b)

See

https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation

Since

0.0.0

Throws

If result exceeds maximum value

Example

import * as Uint8 from './primitives/Uint8/index.js';
const a = Uint8.from(10);
const b = Uint8.from(5);
const product = Uint8.times(a, b); // 50

toBigint()

toBigint(uint): bigint
Defined in: src/primitives/Uint8/toBigint.js:16 Convert Uint8 to bigint

Parameters

uint
Uint8Type Uint8 value

Returns

bigint bigint value

See

https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation

Since

0.0.0

Throws

Example

import * as Uint8 from './primitives/Uint8/index.js';
const value = Uint8.from(255);
const bigintValue = Uint8.toBigint(value); // 255n

toBytes()

toBytes(uint): Uint8Array<ArrayBufferLike>
Defined in: src/primitives/Uint8/toBytes.js:16 Convert Uint8 to Uint8Array (1 byte)

Parameters

uint
Uint8Type Uint8 value

Returns

Uint8Array<ArrayBufferLike> Uint8Array of length 1

See

https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation

Since

0.0.0

Throws

Example

import * as Uint8 from './primitives/Uint8/index.js';
const value = Uint8.from(255);
const bytes = Uint8.toBytes(value); // Uint8Array([255])

toHex()

toHex(uint, padded?): string
Defined in: src/primitives/Uint8/toHex.js:21 Convert Uint8 to hex string

Parameters

uint
Uint8Type Uint8 value
padded?
boolean = true Whether to pad to 2 characters (1 byte)

Returns

string Hex string with 0x prefix

See

https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation

Since

0.0.0

Throws

Example

import * as Uint8 from './primitives/Uint8/index.js';
const value = Uint8.from(255);
const hex1 = Uint8.toHex(value); // "0xff"
const hex2 = Uint8.toHex(value, false); // "0xff"
const value2 = Uint8.from(15);
const hex3 = Uint8.toHex(value2); // "0x0f"
const hex4 = Uint8.toHex(value2, false); // "0xf"

toNumber()

toNumber(uint): number
Defined in: src/primitives/Uint8/toNumber.js:16 Convert Uint8 to number

Parameters

uint
Uint8Type Uint8 value

Returns

number number value

See

https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation

Since

0.0.0

Throws

Example

import * as Uint8 from './primitives/Uint8/index.js';
const value = Uint8.from(255);
const num = Uint8.toNumber(value); // 255

toString()

toString(uint): string
Defined in: src/primitives/Uint8/toString.js:17 Convert Uint8 to decimal string

Parameters

uint
Uint8Type Uint8 value

Returns

string Decimal string representation

See

https://voltaire.tevm.sh/primitives/uint8 for Uint8 documentation

Since

0.0.0

Throws

Example

import * as Uint8 from './primitives/Uint8/index.js';
const value = Uint8.from(255);
const str = Uint8.toString(value); // "255"