# Number.BitwiseOr

## #

But what exactly is a bitwise OR operation? How does it work? And what is the M code behind the Number.BitwiseOr function? In this article, we’ll explore the answers to these questions and more.

## Understanding Bitwise OR Operations

Before we dive into the M code behind the Number.BitwiseOr function, it’s important to understand what a bitwise OR operation is and how it works.

At its most basic level, a bitwise OR operation compares two binary numbers bit by bit and returns a new binary number that has a 1 in each bit position where at least one of the corresponding bits in the original numbers was a 1.

For example, let’s say we want to perform a bitwise OR operation on the numbers 5 and 3. In binary form, these numbers are represented as follows:

– 5: 101

– 3: 011

To perform the bitwise OR operation, we compare each bit from left to right and return a new binary number that has a 1 in each position where at least one of the bits in the original numbers was a 1. In this case, the result would be:

– Result: 111

## The M Code Behind Number.BitwiseOr

Now that we understand what a bitwise OR operation is and how it works, let’s take a look at the M code behind the Number.BitwiseOr function.

The M code for Number.BitwiseOr is surprisingly simple. Here it is:

(x as number, y as number) => x bitwise or y

``` This code defines the Number.BitwiseOr function and specifies that it takes two arguments, x and y, both of which are numbers. The function then performs a bitwise OR operation on x and y using the "bitwise or" operator. It's worth noting that the "bitwise or" operator is not a standard mathematical operator like addition or multiplication. Instead, it's a logical operator that works on individual bits within a binary number. Using Number.BitwiseOr in Power Query Now that we know what the Number.BitwiseOr function does and how it works, let's take a look at some examples of how we can use it in Power Query. Example 1: Bitwise OR on Two Numbers The simplest example of using Number.BitwiseOr is to perform a bitwise OR operation on two numbers. Let's say we have the following two numbers: - Number 1: 5 - Number 2: 3 To perform a bitwise OR operation on these numbers in Power Query, we can use the following code: ```

Number.BitwiseOr(5, 3)

``` This will return the value 7, which is the result of performing a bitwise OR operation on the numbers 5 and 3. Example 2: Using Bitwise OR with Other Functions Number.BitwiseOr can also be used in combination with other functions in Power Query. For example, let's say we have the following table, which contains a column of binary numbers: ```

| Binary Number |

|—————|

| 101 |

| 011 |

| 111 |

``` To perform a bitwise OR operation on each of these numbers and return the result as a decimal number, we can use the following code: ```

= Table.AddColumn(#”Previous Step”, “Decimal Number”, each Number.BitwiseOr( Number.FromText([Binary Number]), 0, 2 ))

``` This will create a new column called "Decimal Number" that contains the decimal representation of each binary number after performing a bitwise OR operation with the value 0. In conclusion, the Number.BitwiseOr function is a powerful tool in Power Query that allows you to perform bitwise OR operations on two numbers. By understanding how bitwise OR operations work and the M code behind the Number.BitwiseOr function, you can unlock the full potential of this function and use it to solve complex data problems. Power Query and M Training Courses by G Com Solutions (0800 998 9248) Power Query and M Intensive Training Course £1,050.00 – £26,550.00 Select optionsContinue Loading Done Power Query and M Introduction £395.00 – £9,750.00 Select optionsContinue Loading Done Power Query and M Intermediate £395.00 – £9,750.00 Select optionsContinue Loading Done Power Query and M Advanced £395.00 – £9,750.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) ```
``` ```
``` ```
``` ```
``` ```
``` ```