# BinaryFormat.SignedInteger32

## #

The M code behind the BinaryFormat.SignedInteger32 function is relatively simple. It takes a binary value as input and returns an integer value with a length of 32 bits. Here’s the M code for the BinaryFormat.SignedInteger32 function:

let

BinaryToInt32 = (binary) =>

let

binaryAsList = Binary.ToList(binary),

paddedBinary = List.Combine({List.Repeat({0}, 32 – List.Count(binaryAsList)), binaryAsList}),

magnitude = List.Accumulate(

0,

(state, current) => state 2 + Number.FromBinary(current)

)

in

if sign = 0 then magnitude else magnitude – 2147483648

in

BinaryToInt32

``` Let's break down this code for a better understanding: - The BinaryFormat.SignedInteger32 function takes one parameter, which is the binary data to be converted to an integer. - The Binary.ToList function converts the binary data into a list of 1's and 0's. - The List.Repeat function adds padding to the binary data so that it has a total of 32 bits. - The List.Combine function combines the original binary data and the padded bits into a single list. - The Number.FromBinary function converts the first bit of the binary data to a number, which represents the sign of the integer. - The List.Skip function removes the first bit of the binary data, leaving only the magnitude of the integer. - The List.Accumulate function combines the remaining bits of the binary data into a single integer value. - Finally, the function returns the signed 32-bit integer value, with a magnitude of the binary data and the sign determined by the first bit. In conclusion, the M code behind the BinaryFormat.SignedInteger32 function is a straightforward and efficient way to convert binary data into signed 32-bit integers. This function is an excellent tool for data analysts who work with binary data regularly, and it can save a lot of time and effort. Power Query and M Training Courses by G Com Solutions (0800 998 9248) Power Query and M Intensive Training Course £1,260.00 – £31,860.00 Select optionsContinue Loading Done Power Query and M Introduction £474.00 – £11,700.00 Select optionsContinue Loading Done Power Query and M Intermediate £474.00 – £11,700.00 Select optionsContinue Loading Done Power Query and M Advanced £474.00 – £11,700.00 Select optionsContinue Loading Done Upcoming Courses Contact Us Subject Your Name (required) Company/Organisation Email (required) Telephone Training Course(s) Power BI Intensive TrainingPower BI introduction Power BI IntermediatePower BI AdvancedDAXPower Query MPower BI CertificationPower BI AdministrationPower PlatformPower AutomatePower AppsOTHER Your Message Upload Example Document(s) (Zip multiple files) ```
``` ```
``` ```
``` ```
``` ```
``` ```