bin.toArray()
bin.toArray(data, format, [byteOrder]) → array
Unpacks binary data into an array of numbers or bits.
The inverse of bin.fromArray() — interprets packed binary data as an array
of the given type. Use it on data from bin.fromHex(), Modbus reads or MQTT
binary messages.
Arguments
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| data | buffer | binary | yes | — | The packed binary data to unpack. |
| format | string | yes | — | Element type — same set as bin.fromArray(), including "BITS"/"RBITS". |
| byteOrder | string | optional | "ABCD" | Byte order (see the class notes). Not used by bit types. |
Returns
array
The unpacked values.
Example
let bytes = bin.fromHex("01fe");
let bitArray = bin.toArray(bytes, "RBITS");
print("bits:", string(bitArray));
let floats = bin.toArray(bin.fromHex("e6b74640000042c8"), "F32", "BADC");