Binary.FromText

Binary.FromText

D

The M Code Behind the Power Query M function Binary.FromText

What is Binary Data?

Binary data is a type of data that is represented as a sequence of 0s and 1s. It is used to represent many different types of data, such as images, audio files, and computer programs. Binary data is often stored in files as a stream of bytes, where each byte is a sequence of 8 bits (0s and 1s).

How Does Binary.FromText Work?

Binary.FromText is a function in M that takes a text string as input and returns a binary value. The text string must represent binary data in a specific format, which is called a hexadecimal string. A hexadecimal string is a sequence of characters that represents binary data as a series of hexadecimal digits.

For example, the binary data represented by the hexadecimal string “4D 5A” is the first two bytes of a Windows executable file. The Binary.FromText function can convert this string into its corresponding binary representation, which is the byte sequence 4D 5A.

Here is an example of how to use Binary.FromText in Power Query:


let

binaryText = "4D5A",

binaryValue = Binary.FromText(binaryText)

in

binaryValue


This code creates a variable called binaryText, which contains the hexadecimal string “4D5A”. It then calls the Binary.FromText function with this string as input, and assigns the result to a variable called binaryValue. The result is a binary value that represents the byte sequence 4D 5A.

How to Convert Binary Data to Text

Sometimes you may need to convert binary data into a text string, for example, when you are working with text-based file formats like CSV or XML. You can use the Text.FromBinary function in M to do this.

Here is an example of how to use Text.FromBinary in Power Query:


let

binaryValue = #binary({0x48, 0x65, 0x6C, 0x6C, 0x6F}),

textValue = Text.FromBinary(binaryValue)

in

textValue


This code creates a variable called binaryValue, which contains a binary value that represents the ASCII string “Hello”. It then calls the Text.FromBinary function with this binary value as input, and assigns the result to a variable called textValue. The result is a text string that contains the characters “Hello”.

The Binary.FromText function in Power Query is a powerful tool for working with binary data. It allows you to easily convert text strings that represent binary data into their corresponding binary representation. By combining this function with other functions in M, you can manipulate and transform binary data in many different ways.

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)