Transform - Numbers: Bit Logic

The Bit Logic template appears in the template list when a numeric field of type float32, float64, int8, int16, int32, int64uint8, uint16, uint32, or uint6, has been picked in the Transform pane.

 

Bit Logic

Perform a bitwise logical operation on the source field, using the specified field, value, or expression for and, or, and xor operations,  and save the result into the specified Result destination using the specified numeric type.

 

  • and - Bitwise logical AND operation between the source field and the second specified field, value or expression result.
  • not - Bitwise logical inversion changing bits from 1 to 0 and from 0 to 1.
  • or - Bitwise logical OR operation between the source field and the second specified field, value or expression result.
  • xor - Bitwise logical XOR operation between the source field and the second specified field, value or expression result.

 

  It makes no sense to use bitwise operators if we do not know the numeric type of the field, and how various numeric types are represented as binary numbers.

 

Launch the template by choosing a numeric field and then double-clicking the Bit Logic template.  When the template launches we can specify options.

 

 

Bit Logic : and

Perform a bitwise logical AND operation between the source field and the second specified field, value or expression result, and save the result to the specified Result destination.  

 

We start with a table with two fields of uint8 type.   We have used the Layers pane to hide the mfd_id field, for a simpler illustration.

 

 

With the focus on the table window, in the Transform pane we choose the Integer A field and then we double-click the Bit Logic template to launch it.

 

 

In the Bit Logic template, we choose and as the Operation.    

 

For the Value field, we choose the Integer B field from the pull down menu.  We could also have chosen to enter a specific value, or an Expression.

 

For the Result destination, we choose New Field and then enter Bitwise AND as the name of the new field to add to the table.  We could use whatever name we want, but it is wise to use names that remind us of what they are supposed to be.     For the Result type we choose uint8, so the result can be compared to the original source fields.

 

If we preferred, we could have chosen Same Field to write the result back to the Integer A field, updating it "in place," or we could have chosen some other existing numeric field in the table.

 

Press Transform.  

 

 

The template creates a new uint8 type field called Bitwise AND and populates it with the results of a bitwise AND operation between the Integer A and Integer B fields.

 

Because the binary function operates on each bit in the uint8 types in the table, only when all eight bits of the value match does the AND provide a non-zero result for each bit.  In this case that happens only in the second record.

 

Bit Logic : not

Performs a bitwise NOT operation on  the source field, and save the result to the specified Result destination.   A bitwise NOT operation  is a bitwise logical inversion, changing bits from 1 to 0 and from 0 to 1.

 

We start with a table with one of uint8 type.   We have used the Layers pane to hide the mfd_id field, for a simpler illustration.

 

 

With the focus on the table window, in the Transform pane we choose the Integer A field and then we double-click the Bit Logic template to launch it.

 

 

In the Bit Logic template, we choose not as the Operation.    

 

For the Result destination, we choose New Field and then enter Bitwise NOT as the name of the new field to add to the table.  We could use whatever name we want, but it is wise to use names that remind us of what they are supposed to be.   For the Result type we choose uint8, so the result can be compared to the original source field.

 

If we preferred, we could have chosen Same Field to write the result back to the Integer A field, updating it "in place," or we could have chosen some other existing numeric field in the table.

 

Press Transform.  

 

 

The template creates a new uint8 type field called Bitwise NOT and populates it with the results of a bitwise NOT operation on the Integer A field.

 

Inverting all binary bits for the uint8 value 0 would result in 255.  Inverting each Integer A representation as a binary in effect counts down by 1 in the Bitwise NOT result as Integer A counts up by 1.

 

Bit Logic : or

Perform a bitwise logical OR operation between the source field and the second specified field, value or expression result, and save the result to the specified Result destination.  

 

We start with a table with two fields of uint8 type.   We have used the Layers pane to hide the mfd_id field, for a simpler illustration.

 

 

With the focus on the table window, in the Transform pane we choose the Integer A field and then we double-click the Bit Logic template to launch it.

 

 

In the Bit Logic template, we choose or as the Operation.    

 

For the Value field, we choose the Integer B field from the pull down menu.  We could also have chosen to enter a specific value, or an Expression.

 

For the Result destination, we choose New Field and then enter Bitwise OR as the name of the new field to add to the table.  We could use whatever name we want, but it is wise to use names that remind us of what they are supposed to be.     For the Result type we choose uint8, so the result can be compared to the original source fields.

 

If we preferred, we could have chosen Same Field to write the result back to the Integer A field, updating it "in place," or we could have chosen some other existing numeric field in the table.

 

Press Transform.  

 

 

The template creates a new uint8 type field called Bitwise OR and populates it with the results of a bitwise OR operation between the Integer A and Integer B fields.

 

The binary representation of 2 in a uint8 data type are the same for both integer fields, matching exactly for all bits so the result is 2 as well.  For all cases where the value of Integer B is 0 the result is simply whatever is in Integer A.  In the fourth record, the one case where the two fields are different and Integer B is not zero, the OR operation results in a bitwise addition, adding the single binary "on" bit for the value of 1 to the binary pattern for 4 to get a result of 5.

 

Bit Logic : xor

Perform a bitwise logical XOR operation between the source field and the second specified field, value or expression result, and save the result to the specified Result destination.  

 

We start with a table with two fields of uint8 type.   We have used the Layers pane to hide the mfd_id field, for a simpler illustration.

 

 

With the focus on the table window, in the Transform pane we choose the Integer A field and then we double-click the Bit Logic template to launch it.

 

 

In the Bit Logic template, we choose xor as the Operation.    

 

For the Value field, we choose the Integer B field from the pull down menu.  We could also have chosen to enter a specific value, or an Expression.

 

For the Result destination, we choose New Field and then enter Bitwise XOR as the name of the new field to add to the table.  We could use whatever name we want, but it is wise to use names that remind us of what they are supposed to be.     For the Result type we choose uint8, so the result can be compared to the original source fields.

 

If we preferred, we could have chosen Same Field to write the result back to the Integer A field, updating it "in place," or we could have chosen some other existing numeric field in the table.

 

Press Transform.  

 

 

The template creates a new uint8 type field called Bitwise XOR and populates it with the results of a bitwise XOR operation between the Integer A and Integer B fields.

 

The Boolean XOR function generates a FALSE when both inputs are TRUE.   The result in a bitwise comparison is a FALSE, or 0 when all bits in both source fields are identical.  That only happens in our example in the second record where all of the bits are the same when the two values are both the same, 2, thus creating a result of 0.  In all of the other cases where the two values are different the result is similar to that of the Binary Or operator.

 

 

See Also

Transform Pane

 

Transform Reference

 

Transform - Expression

 

Transform - Numeric Vectors

 

Transform - Numbers

 

Transform - Numbers: Arithmetic

 

Transform - Numbers: Copy

 

Transform - Numbers: Expression

 

Transform - Numbers: Hyperbolic

 

Transform - Numbers: Limit

 

Transform - Numbers: Round

 

Transform - Numbers: Special

 

Transform - Numbers: Trigonometric