Controlling byte order

D

T

The M Code Behind the Power Query M function Controlling byte order

What is Byte Order?

Before we dive into the M code behind controlling byte order, it is essential to understand what byte order means. Byte order refers to the order in which bytes are arranged to represent data. There are two common byte order formats: Little-Endian and Big-Endian.

In the Little-Endian format, the least significant byte is stored first, followed by the next least significant byte, and so on until the most significant byte is stored last. In contrast, the Big-Endian format stores the most significant byte first, followed by the next most significant byte, and so on until the least significant byte is stored last.

Byte order is essential when working with binary data, such as network packets or file formats. If byte order is not correctly considered, data can be misinterpreted, resulting in errors or incorrect results.

Controlling Byte Order in Power Query

Power Query is a powerful tool for working with data, and its M function provides a simple way of controlling byte order when handling binary data. The M function can be used to read data in both Little-Endian and Big-Endian formats and convert between them.

The M function provides the following functions for controlling byte order:

ByteOrder.LittleEndian

The ByteOrder.LittleEndian function specifies that data should be read in Little-Endian format.

ByteOrder.BigEndian

The ByteOrder.BigEndian function specifies that data should be read in Big-Endian format.

Binary.ToText

The Binary.ToText function can be used to convert binary data to text and specify the byte order format. By default, Binary.ToText assumes Little-Endian format, but this can be changed by specifying the ByteOrder parameter.

Binary.FromText

The Binary.FromText function can be used to convert text to binary data and specify the byte order format. By default, Binary.FromText assumes Little-Endian format, but this can be changed by specifying the ByteOrder parameter.

Byte order is an important consideration when working with binary data, and Power Query’s M function provides a simple and effective way of controlling it. By using the ByteOrder.LittleEndian and ByteOrder.BigEndian functions, along with the Binary.ToText and Binary.FromText functions, you can ensure that data is read and written in the correct byte order format.

In summary, the M code behind the Power Query M function provides a straightforward way of controlling byte order when working with data. By understanding byte order and how to use the M function, you can ensure that your data is accurately processed and avoid errors or incorrect results.

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)