BinaryFormat.UnsignedInteger32

D

T

The M Code Behind the Power Query M function BinaryFormat.UnsignedInteger32

What is BinaryFormat.UnsignedInteger32?

BinaryFormat.UnsignedInteger32 is a function that is used to convert binary data, represented as a byte array, into 32-bit unsigned integers. The function takes two arguments: the binary data and the byte order. The byte order specifies whether the most significant byte or the least significant byte comes first in the byte array.

The M Code Behind BinaryFormat.UnsignedInteger32

To understand the M code behind BinaryFormat.UnsignedInteger32, let’s take a look at an example. Consider the following byte array:

`{0x01, 0x02, 0x03, 0x04}`

This byte array represents the unsigned 32-bit integer 0x04030201 in little-endian byte order. To convert this byte array into an unsigned 32-bit integer using the BinaryFormat.UnsignedInteger32 function, we can use the following M code:


let

binary = {0x01, 0x02, 0x03, 0x04},

uint32 = BinaryFormat.UnsignedInteger32(binary, ByteOrder.LittleEndian)

in

uint32


Let's break down this code. First, we define a variable `binary` that contains the byte array `{0x01, 0x02, 0x03, 0x04}`. Then, we call the BinaryFormat.UnsignedInteger32 function and pass in the `binary` variable as well as the ByteOrder.LittleEndian value to specify the byte order. Finally, we assign the result to a variable `uint32`.

Byte Order

Byte order is an important consideration when working with binary data. It specifies whether the most significant byte or the least significant byte comes first in the byte array. There are two byte orders: big-endian and little-endian.

In big-endian byte order, the most significant byte comes first in the byte array. In little-endian byte order, the least significant byte comes first in the byte array. Most modern computers use little-endian byte order, but some older computers and network protocols use big-endian byte order.

To specify the byte order in the BinaryFormat.UnsignedInteger32 function, we can use the ByteOrder.LittleEndian or ByteOrder.BigEndian value.

In this article, we have explored the M code behind the BinaryFormat.UnsignedInteger32 function in Power Query. This function is used to convert binary data into unsigned 32-bit integers. We have also discussed the importance of byte order when working with binary data and how to specify the byte order in the BinaryFormat.UnsignedInteger32 function.

Power Query is a powerful tool for data transformation and cleaning, and the BinaryFormat.UnsignedInteger32 function is just one example of its capabilities. With its ease of use and flexibility, Power Query is a valuable tool for any data professional.

Power Query and M Training Courses by G Com Solutions (0800 998 9248)

Upcoming Courses

Contact Us

    Subject

    Your Name (required)

    Company/Organisation

    Email (required)

    Telephone

    Training Course(s)

    Your Message

    Upload Example Document(s) (Zip multiple files)