Logic Modules

Logic operations come in two flavors, value operations and bitwise operations. Value operations treat the entire value as a logical parameter. Either it is 0 and is considered Logical False, or it is anything else and is considered Logical True. Bitwise operations treat the individual binary digits (bits) as separate parameters, and return a value based on the logical operation of the individual bits. Often, as when True is represented as the numerical value 1 (which is the standard for ArtWonk modules), the the binary operation and the value operation on 1 as True, 0 as False, are one and the same.

The ArtWonk Logic module menu is grouped into three sections. The first is for Boolean operations on the entire value, with 0 as False and anything else, ("Not Zero" or "NZ") as True. The second section is for bitwise logical operations. These treat the value as a 32 bit integer and the logical operations are performed on the individual bits. And the third section is for logical modules that do not fit neatly into either of the first two sections.


Boolean Value Operators: Not TestBit SetBit Num2Bits Bits2Num

Bitwise Value Operators: AND ANDx OR ORx XOR Invert Shift

Mixed Logic Operations: Compare Equal NotEqual Greater GrEqual


Boolean Value Operators

Modules in this group operate on input parameters as a single boolean value. 0 is logical False, and anything not zero is logical True. Output from these modules is either 0 for False, or 1 for True.


Not

Reverses the Boolean value of the input.

Output:

Not: The logical NOT of the input value. If the input is False (0) this output will be True (1); if the input is True (any NZ) the output will be False (0).

Input:

In: Any numerical value. 0 is considered logical False, NZ is logical True.


TestBit

Test if a bit is on or off. Assumes a 32 bit integer value to test, tests given bit number (0-31) returning True if bit is on, False if bit is off.

Output:

Out: True (1) if bit is on, False (0) if off.

Input:

Bit: Bit number (0-31) to test.

In: Integer value to test.


SetBit

Set or clear a bit. Assumes a 32 bit integer value, sets/clears given bit number (0-31).

Output:

Out: Value after bit is set/cleared.

Input:

Bit: Bit number (0-31) to set or clear.

In: Integer value to change.

Set: 0 to clear bit, NZ to set bit.


Num2Bits

Convert a value to its separate True (1) or False (0) bits in individual outputs. Assumes a 32 bit integer value. Works with a user settable number of outputs, up to 32. To change the number of outputs, click on the blue-label property button on the upper right of the module, and click on the "More" or "Fewer" button on the Outputs tab. You have the option to set custom output labels and tool tips if you like.

Outputs:

Bit 0 ... Bit 31: Value of the bit at the bit position of the output. Outputs will be True (1) if the bit in the input number is on, and False (0) if it is off. For example the number 6 (binary 0110) would put 1 in the Bit 1 and Bit 2 outputs, with all other outputs at 0.

Input:

Num: The value to convert to separate bit flags. This should be a value within the 32 bit integer range of -2,147,483,648 to 2,147,483,647. Values outside this range will give errors.


Bits2Num

Convert up to 32 separate values into a single number that represents the bit-truth of the inputs. Each input is treated as logical True or False, with 0 as False and anything not zero (including negative values) as True. The output is treated as a 32 bit binary integer, with each bit of the integer set or cleared according to the bit inputs. Works with a user settable number of inputs, up to 32. To change the number of inputs, click on the blue-label property button on the upper right of the module, and click on the "More" or "Fewer" button on the Inputs tab. You have the option to set custom input labels and tool tips if you like.

Output:

Num: The value of the converted input bit flags.

Inputs:

Bit 0 ... Bit 31: True or False, with 0 as False and anything not zero (including negative values) as True. Value at the inputs will be set or cleared in the output value. For example if Bit 0 and Bit 1 is set to True and all other inputs are set to False, the output will be 3 (binary 0011).


Bitwise Value Operators

Modules in this group operate on input parameters as binary digits. All parameters are considered 32 bit integers. Decimal fractions are truncated. Output is a value based on the bit operations. Note that you can hold the mouse cursor over module outputs to get a tool tip that shows the hexadecimal representation of the value, which often makes bit patterns easier to visualize.


AND

The Boolean logical AND function is that if either of two operands is False, the result will be False; both have to be True for the result to be True. Thus, the AND function works something like digital masking tape, and in fact the AND function is sometimes called a masking function.

To illustrate, say you have some random value and you want to isolate only the least significant 3 bits, to give you a value range of 0-7 (binary 7 is 111). To do this, put the unknown value into one input of an And module, and put 7 into the other input. This masks out all bits other than the lower 3 (anything AND 0 is always 0), so your result will always be in the 0-7 range. This particular trick works with any power of 2 -1 number, such as 1 (2-1), 3 (4-1), 7 (8-1), 15 (16-1), and so on.

Output:

Out: Bitwise logical AND of the two inputs.

Inputs:

In 1: Any value, but it is converted to a 32 bit integer with truncation of the fractional part prior to processing.

In 2: Any value, converted to a 32 bit integer.


ANDx

This is an AND function on a user settable number of inputs ("x" stands for eXpandable). To change the number of inputs, click on the blue-label property button on the upper right of the module, and click on the "More" or "Fewer" button on the Inputs tab. You have the option to set custom input labels and tool tips if you like.

This module has dual outputs, one for bitwise operations and one for Boolean value operations. The difference is the bitwise operation is exactly the same as the standard AND module, but the value operation first converts the input to 1 if it is logican True, and performs the AND function only on the 1's and 0's that are the logical truth of the entire input, not the bits of the input.

Outputs:

Bits: Bitwise (operates on individual bits) AND of Inputs.

Logic: Logical (converts inputs to 0 or 1) AND of Inputs

Inputs:

In x: Any value, but it is converted to a 32 bit integer with truncation of the fractional part prior to processing bitwise, and converted to 0 or 1 prior to logic processing.


OR

The Boolean logical OR function is that if any one of any number of operands is True, the result is True; all must be False for a result of False.

The OR module is handy for combining logical outputs from other modules. A great way to produce complex rhythm patterns is to set up multiple Clock or Event modules of different durations and then use OR to combine the outputs.

The OR function is always bitwise, however the resulting truth of the operation works the same whether you are treating it as a bitwise operation or a logical operation on the entire value.

Output:

Out: Bitwise logical OR of the two inputs.

Inputs:

In 1: Any value, but it is converted to a 32 bit integer with truncation of the fractional part prior to processing.

In 2: Any value, converted to a 32 bit integer.


ORx

This is an OR function on a user settable number of inputs ("x" stands for eXpandable). To change the number of inputs, click on the blue-label property button on the upper right of the module, and click on the "More" or "Fewer" button on the Inputs tab. You have the option to set custom input labels and tool tips if you like.

Outputs:

Bits: Bitwise (operates on individual bits) OR of Inputs.

Inputs:

In x: Any value, but it is converted to a 32 bit integer with truncation of the fractional part prior to processing.


XOR

The Boolean logical Exclusive OR or XOR function is that if the two operands are different the result is True, if they are the same, the result is False. You can think of XOR as a bit inverter. For every On bit in one operand, the result will be the reverse of the corresponding bit in the other operand. To put it another way, if you set one operand to all 1's (in ArtWonk this would be -1 or &hFFFFFFFF), XOR acts as a bit-by-bit NOT on the other operand.

Output:

Out: Bitwise logical XOR of the two inputs.

Inputs:

In 1: Any value, but it is converted to a 32 bit integer with truncation of the fractional part prior to processing.

In 2: Any value, converted to a 32 bit integer.


Invert

This is a bitwise inversion of the input. Each bit is individually flipped, 1s become 0s, and 0s become 1s. Note that this is different from the NOT module, which is a logical NOT of the logical truth of the input as a whole; Invert is a bit by bit logical NOT.

Output:

Out: Bitwise logical NOT of the input.

Inputs:

In: Any value, but it is converted to a 32 bit integer with truncation of the fractional part prior to processing.


Shift

Bitwise shift or rotate input value.

Output:

Out: Shifted value.

Inputs:

In: Value to Shift.

Shift: Number of bits (0-31) to Shift.

Op: Shift Operation: 0=Shift Right, 1=Shift Left, 2=Rotate Right, 3=Roate Left.


Mixed Logic Operations

Modules in this group do not fall neatly in either of the above two classifications.


Compare

Compares two inputs and returns the logical truth (0 for False; 1 for True) of the comparison. Three simultainous compares of A against B are done, which gives results for A - B; to get results of B - A (as, is A < B?) simply reverse the the inputs.

Outputs:

A=B: True (1) if the value of input A is equal to input B.

A>=B: True (1) if the value of input A is equal to or greater than input B, or if B is less than or equal to A.

A>B: True (1) if the value of input A is greater than input B, or if B is less than A.

Inputs:

In A: Any numeric value.

In B: Any numeric value.


Equal

Outputs:

A=B: True (1) if the value of input A is equal to input B.

Inputs:

In A: Any numeric value.

In B: Any numeric value.


NotEqual

Compares two inputs for non-equality.

Outputs:

A<>B: True (1) if the value of input A is not equal to input B.

Inputs:

In A: Any numeric value.

In B: Any numeric value.


Greater

Outputs:

A>B: True (1) if the value of input A is greater than input B, or if B is less than A.

Inputs:

In A: Any numeric value.

In B: Any numeric value.


GrEqual

Outputs:

A>=B: True (1) if the value of input A is equal to or greater than input B, or if B is less than or equal to A.

Inputs:

In A: Any numeric value.

In B: Any numeric value.

ArtWonk is Copyright 2003-2014 by John Dunn and Algorithmic Arts. All Rights Reserved.