Try it Live
Run Int examples in the interactive playground
Type Definition
Brandedbigint representing signed 128-bit integer (-2^127 to 2^127-1). Supports two’s complement encoding for hex/bytes operations.
Range
- MIN: -2^127 = -170141183460469231731687303715884105728
- MAX: 2^127-1 = 170141183460469231731687303715884105727
- Size: 16 bytes (128 bits)
Quick Start
API Methods
Constructors
from(value)- From bigint, number, or stringfromBigInt(value)- From bigint with validationfromNumber(value)- From number (throws if out of range)fromHex(hex)- Parse hex (two’s complement)fromBytes(bytes)- Parse bytes (two’s complement, big-endian)
Conversions
toHex(value)- To hex (two’s complement)toBytes(value)- To bytes (16 bytes, two’s complement, big-endian)toBigInt(value)- To biginttoNumber(value)- To number (throws if unsafe)toString(value)- To decimal string
Arithmetic
plus(a, b)- Add with wrappingminus(a, b)- Subtract with wrappingtimes(a, b)- Multiply with wrappingdividedBy(a, b)- Divide (truncate toward zero)modulo(a, b)- Modulo (sign follows dividend)abs(value)- Absolute value (throws on MIN)negate(value)- Negate with wrapping
Comparison
equals(a, b)- EqualitylessThan(a, b)- Signed less thangreaterThan(a, b)- Signed greater thanisZero(value)- Check if zeroisNegative(value)- Check if negativeisPositive(value)- Check if positivesign(value)- Sign indicator (-1, 0, 1)minimum(a, b)- Minimum valuemaximum(a, b)- Maximum value
Bitwise
bitwiseAnd(a, b)- Bitwise ANDbitwiseOr(a, b)- Bitwise ORbitwiseXor(a, b)- Bitwise XORbitwiseNot(value)- Bitwise NOTshiftLeft(value, shift)- Left shiftshiftRight(value, shift)- Arithmetic right shift (sign-preserving)
Utilities
bitLength(value)- Significant bit countleadingZeros(value)- Leading zero countpopCount(value)- Set bit countisValid(value)- Range validation
Two’s Complement
Int128 uses two’s complement for hex/bytes encoding:Division Semantics
Division truncates toward zero (not floor):Arithmetic Right Shift
shiftRight preserves sign (arithmetic shift):

