toFixedString(num: number, count: number)
Description
Convert a number to a string of the specified length; pad with leading zeros if shorter, truncate from the right if longer
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
num | number | Yes | Number to convert |
count | number | Yes | The fixed length of the target string |
Return Value
Examples
Basic usage
toFilledString(num: number, count: number)
Description
Convert a number to a string with a specified minimum length; pad with leading zeros if shorter, keep as is if longer
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
num | number | Yes | Number to convert |
count | number | Yes | The minimum length of the target string |
Return Value
Examples
Basic usage
bytesToHexString(bytes: number[])
Description
Convert a byte array to a hex string
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
bytes | number[] | Yes | Byte array; each element is an integer from 0 to 255 |
Return Value
Examples
Basic usage
numToByteNumbers(num: number, bytes?: number)
Description
Convert a decimal integer to a big-endian byte array
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
num | number | Yes | The decimal integer to convert |
bytes | number | No | Minimum byte count (default 2); if the result is shorter than this length, pad zeros on the high-order side |
Return Value
Examples
Basic usage
intToHighLow(num: number)
Description
Split an integer into an array of high and low bytes
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
num | number | Yes | Integer to split |
Return Value
Examples
Basic usage
inMaxMin(min: number, max: number, value: number)
Description
Clamp a value between a minimum and a maximum
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
min | number | Yes | Minimum allowed value |
max | number | Yes | Maximum allowed value |
value | number | Yes | Value to clamp |
Return Value
Examples
Basic usage
scaleNumber(scale: number, value: number)
Description
Scale a number by the specified precision and return a string
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
scale | number | Yes | Scale precision: divide by 10^scale and keep scale decimal places |
value | number | Yes | Value to scale |
Return Value
Examples
Basic usage
range(start: number, end: number, step?: number)
Description
Generate an array of numbers within a specified range
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
start | number | Yes | Start value |
end | number | Yes | End value |
step | number | No | Step value, defaults to 1 |
Return Value
Examples
Basic usage
calcPosition(value: number, min: number, max: number, newMin: number, newMax: number)
Description
Linearly map a value from one range to another
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
value | number | Yes | Original value |
min | number | Yes | Minimum of the original range |
max | number | Yes | Maximum of the original range |
newMin | number | Yes | Minimum of the target range |
newMax | number | Yes | Maximum of the target range |
Return Value
Examples
Basic usage
calcPercent(min: number, max: number, value: number, offset?: number)
Description
Compute the percentage of a value within a specified range
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
min | number | Yes | Range minimum |
max | number | Yes | Range maximum |
value | number | Yes | The value to compute, which will be clamped to [min, max] |
offset | number | No | Percentage start offset (0–1), defaults to 0 |
Return Value
Examples
Basic usage
getBitValue(num: number, idx: number)
Description
Get the bit value at the specified position in a number's binary representation
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
num | number | Yes | Input number |
idx | number | Yes | Bit index (starting from the least significant bit; 0 is the LSB) |
Return Value
Examples
Basic usage
changeBitValue(num: number, idx: number)
Description
Flip the bit at the specified position in a number's binary representation (0 becomes 1, 1 becomes 0)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
num | number | Yes | Input number |
idx | number | Yes | Bit index (starting from the least significant bit; 0 is the LSB) |
Return Value
Examples
Basic usage
setBitValueWithOne(num: number, idx: number)
Description
Set the bit at the specified position to 1 in a number's binary representation
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
num | number | Yes | Input number |
idx | number | Yes | Bit index (starting from the least significant bit; 0 is the LSB) |
Return Value
Examples
Basic usage
setBitValueWithZero(num: number, idx: number)
Description
Set the bit at the specified position to 0 in a number's binary representation
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
num | number | Yes | Input number |
idx | number | Yes | Bit index (starting from the least significant bit; 0 is the LSB) |
Return Value
Examples
Basic usage
numToHexString(num: number, padding?: number)
Description
Convert a decimal number to a hex string with the specified minimum length
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
num | number | Yes | Decimal number to convert |
padding | number | No | Minimum hex string length; defaults to 2, pad with leading zeros if shorter |
Return Value
Examples
Basic usage
highLowToInt(high: number, low: number)
Description
Combine high and low bytes into an integer
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
high | number | Yes | High 8-bit byte value |
low | number | Yes | Low 8-bit byte value |
Return Value
Examples
Basic usage
add(number1: number, number2: number)
Description
Accurately add two numbers to avoid floating-point precision issues
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
number1 | number | Yes | First addend |
number2 | number | Yes | Second addend |
Return Value
Examples
Basic usage
subtract(number1: number, number2: number)
Description
Accurately subtract two numbers to avoid floating-point precision issues
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
number1 | number | Yes | Minuend |
number2 | number | Yes | Subtrahend |