Skip to content

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

ParameterType
nnumber

Returns

Uint8Array&lt;ArrayBuffer&gt;

MIT Licensed. A fork of pdf-lib.