Skip to content

hexValue

function hexValue(n, base?): Value;

Defined in: packages/engine/src/vm/Value.ts:423

Create a Hex-typed Value: a number that displays in another base.

The type is numeric on purpose, and that is the whole point of it. A base is a way of writing a quantity, not a different kind of quantity, so 0xFF + 1 has to be 256. Returning a string instead makes it 1, because a string reads as zero in arithmetic, and nothing about that failure is visible at the point of use.

ParameterTypeDefault valueDescription
nnumber | bigintundefinedThe number itself, in full precision. A bigint is accepted for the same reason the type is numeric at all: 12345678901234567890n as hex has an exact answer, and forcing it through a double first rendered 0xAB54A98CEB1F0800 for a value ending 0AD2.
baseDisplayBase"hex"How to display it, defaulting to hexadecimal. Carried in the unit slot, which is free for this type.

Value