CompactSize.toBytes
Encodes an integer using Bitcoin's CompactSize variable-length encoding.
| Range | Encoding | Bytes | |---|---|---| | 0–252 | Direct value | 1 | | 253–65,535 | 0xFD + 2 bytes LE | 3 | | 65,536–4,294,967,295 | 0xFE + 4 bytes LE | 5 | | > 4,294,967,295 | 0xFF + 8 bytes LE | 9 |
Imports
Named
import { CompactSize } from 'ox'Examples
import { CompactSize } from 'ox'
const bytes = CompactSize.toBytes(252)
// Uint8Array [252]
const bytes2 = CompactSize.toBytes(253)
// Uint8Array [253, 253, 0]Definition
function toBytes(
value: bigint | number,
): Bytes.BytesSource: src/core/CompactSize.ts
Parameters
value
- Type:
bigint | number
The integer to encode.
Return Type
The CompactSize-encoded bytes.
Bytes.Bytes

