How the bitwise math tools work

On a cell-by-cell basis, the bitwise tools evaluate the binary representation of the input values. For each bit in the binary representation, a Boolean operation is performed.

The logic for how the various bitwise tools operate is illustrated in the following sections. The arrows are used to indicate the flow of operation of how input values are converted to a base2 binary representation, analysed, and returned as a decimal (base10) value.

Bitwise And, Or and XOr

  • For Bitwise And, for each bit where both inputs are 1, the output is 1. If one or both bits are 0, the output is 0 for the bit.
  • For Bitwise Or, for each bit where one or both inputs are 1, the output is 1. If both bits are 0, the output is 0 for the bit.
  • For Bitwise XOr, for each bit where one input is 1 and the other 0, the output is 1. If both bits are 1 or both are 0, the output is 0 for the bit.

                  Decimal         Binary  
                  value           value   
                  -------         --------
Input 1                 5    >    00000101
Input 2                 3    >    00000011

                                     V   

Bitwise And             1    <    00000011

Bitwise Or              7    <    00000111

Bitwise XOr             6    <    00000110

Bitwise Not

For Bitwise Not, the bitwise complement of the binary representation of an input value is determined.

This means that for each input bit that is 1, the output is 0. Input bits that are 0 will be output as 1.

                  Decimal         Binary  
                  value           value   
                  -------         --------
Input 1                 5    >    00000101

                                     V    

Bitwise Not            -6    <    11111010

Bitwise Left Shift and Bitwise Right Shift

The arrows in the following illustration demonstrate that the input values are first converted to their binary representation, then the bitwise logic is applied to each pair of bits that represent those values, then the values are finally converted back to a decimal representation.

  • For Bitwise Left Shift, the value for each bit is shifted to the left by the number of bit positions specified in the second input. The value that is assigned to the farthest left bit is lost.

    The effect of a left shift by one bit position is a multiplication by two.

  • For Bitwise Right Shift, the value for each bit is shifted to the right by the number of bit positions specified in the second input. The value that is assigned to the farthest right bit is lost.

    The effect of a right shift by one bit position is a division by two with truncation.

                  Decimal         Binary  
                  value           value   
                  -------         --------
Input 1                 5    >    00000101
Input 2                 1    >    00000001

                                     V    

Bitwise Left Shift     10    <    00001010

Bitwise Right Shift     2    <    00000010

NoteNote:

If any of the input cell values is NoData, the output value will be NoData.

Related Topics

11/8/2012