happypdf / bytesFor
Function: bytesFor()
ts
function bytesFor(n): Uint8Array<ArrayBuffer>;Defined in: src/utils/numbers.ts:47
Converts a number into its constituent bytes and returns them as a number[].
Returns most significant byte as first element in array. It may be necessary to call .reverse() to get the bits in the desired order.
Example: bytesFor(0x02A41E) => [ 0b10, 0b10100100, 0b11110 ]
Credit for algorithm: https://stackoverflow.com/a/1936865
Parameters
| Parameter | Type |
|---|---|
n | number |
Returns
Uint8Array<ArrayBuffer>