# Binary.FromList

## What is the Binary.FromList Function?

The Binary.FromList function in Power Query M is used to convert a list of values into a binary value. The function takes a list of values as an input and returns a binary value. The binary value is a representation of the input list in a binary format.

The Binary.FromList function is useful in a variety of applications where binary values are required. For example, it can be used in cryptography to encrypt and decrypt data, in data compression to compress and decompress data, and in data transmission to send and receive data.

## The M Code Behind Binary.FromList

The M Code behind the Binary.FromList function is relatively simple. The function takes a list of values as an input and converts each value to a binary format. The binary values are then concatenated to create a binary value that represents the input list.

The following is the M Code for the Binary.FromList function:

``` (Binary.FromList) => (list as list) => let binaryList = List.Transform(list, (x) => Number.ToBinary(x)), binaryString = Text.Combine(binaryList, ""), binaryValue = Binary.FromText(binaryString) in binaryValue ```

In this code, the list of values is first transformed using the List.Transform function. The List.Transform function applies a transformation function to each value in the list, in this case the Number.ToBinary function. This function converts each value in the list to a binary format.

The resulting binary values are then concatenated using the Text.Combine function. This function combines the binary values into a single binary string.

Finally, the Binary.FromText function is used to convert the binary string into a binary value.

## Examples of Using Binary.FromList

The Binary.FromList function can be used in a variety of applications. Here are some examples of how it can be used:

### Example 1: Encrypting Data

Suppose we want to encrypt a list of sensitive data. We can use the Binary.FromList function to convert the list of data into a binary value, which can then be encrypted using a cryptographic algorithm.

``` let sensitiveData = {"John Doe", "1234-5678-9012-3456", "johndoe@email.com"}, binaryValue = Binary.FromList(sensitiveData) in binaryValue ```

In this example, the list of sensitive data is first defined. The Binary.FromList function is then used to convert the list into a binary value. This binary value can then be encrypted using a cryptographic algorithm.

### Example 2: Compressing Data

Suppose we have a large list of data that we want to compress to save storage space. We can use the Binary.FromList function to convert the list of data into a binary value, which can then be compressed using a data compression algorithm.

``` let data = {"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas viverra ipsum ac mauris dapibus, ultricies posuere massa accumsan. Sed id diam ut elit mattis bibendum sit amet non nisl. Sed nec nisi at ex vulputate consequat. Sed at risus vel turpis posuere suscipit vel a arcu. Sed lacinia, sem vel aliquet malesuada, ex nulla fringilla odio, id fringilla turpis mauris non risus. Nullam lacus ipsum, suscipit ut est nec, ornare pellentesque orci. Curabitur vel ex vel nisi bibendum commodo quis vel metus. Sed congue urna eu nulla facilisis, ac blandit nulla imperdiet. Nullam lectus orci, placerat a ligula sit amet, rhoncus suscipit arcu. Vivamus vestibulum bibendum elit, a ultricies massa pharetra in. Quisque pharetra semper augue quis facilisis. Sed elementum lacus vel libero ultricies, eu congue sapien bibendum. Donec vel nisi sapien. Sed justo ipsum, vehicula nec felis non, tempor lacinia odio. Nulla facilisi. Sed aliquet enim vel elit malesuada luctus."}, binaryValue = Binary.FromList(data) in binaryValue ```

In this example, the large list of data is first defined. The Binary.FromList function is then used to convert the list into a binary value. This binary value can then be compressed using a data compression algorithm.

### Example 3: Transmitting Data

Suppose we want to transmit a list of data over a network. We can use the Binary.FromList function to convert the list of data into a binary value, which can then be sent over the network.

``` let data = {"John Doe", "1234-5678-9012-3456", "johndoe@email.com"}, binaryValue = Binary.FromList(data), url = "https://example.com/sendData", options = [Content = binaryValue, Headers=[#"Content-Type"="application/octet-stream"]], result = Web.Contents(url, options) in result ```

In this example, the list of data is first defined. The Binary.FromList function is then used to convert the list into a binary value. This binary value is then sent over the network using the Web.Contents function.

The Binary.FromList function in Power Query M is a powerful tool that allows users to convert a list of values into a binary value. Understanding the M Code behind this function can help users to better utilize it in their data analysis projects. By using the examples provided in this article, users can see how the Binary.FromList function can be used in a variety of applications.

Subject