Topic: DMD0537

Help File Version: 2.10.0.636

Math Bit-wise Invert Operator


The Math Bit-wise Invert operator ( ~ ) performs the ones' complement of the given binary value meaning that bits that are 0 become 1, and bits that are 1 become 0.

 

Note: bit-wise Invert operations are typically only used for unsigned hexadecimal values and unsigned integer memory locations. Using the :U cast operator on signed 16-bit values will cause them to be processed as unsigned 16-bit values. There is no unsigned cast operation for 32-bit signed values.

 

The operand can be any mix of signed integers, unsigned integers, real (floating point) numbers or discrete values. They can be any numeric or discrete memory location, or any numeric or discrete structure member.

 

All discrete values and all 16-bit integer values are promoted to 32-bit 2's complement signed integer values. If a Real value is included in the equation then all of the values will be promoted to Real values and all calculations will be performed using Real numbers.

 

Traditional math precedence rules are used to solve the math expression, The use of parentheses to remove any ambiguity in the processing order is encouraged.

 

Unsigned Integers: assume V1 = 0x1234

 

V0 = ~V1

 

V0 = ~0x1234

 

V0 = 0001_0010_0011_0100 (0x1234)
V0 = 1110_1101_1100_1011 (0xEDCB)

 

The operand is an unsigned integer memory location.

 

The result is placed in an unsigned integer memory location.

 

 

As stated earlier, bit-wise operations are intended for use on Unsigned integer values, NOT Signed integer values or Real values. The following examples are here only to provide understanding in how these values will be processed by the math stack, the result that is generated is typically not useful.

 

Signed integers: assume N1 = -1234

 

 

 

 

D0 = ~N1

 

D0 = ~(-1234)

 

D0 = 1111_1111_1111_1111_1111_1011_0010_1110 (-1234)

D0 = 0000_0000_0000_0000_0000_0100_1101_0001 (1233)

 

The operand is a signed integer memory location.

 

When the 16-bit negative value is loaded into the math stack it will be promoted to a 32-bit 2's complement value by sign extending using 1's in the upper 16 bits.

 

The result is placed in a signed integer memory location.

 

 

Real: assume R1 = 12345678.9

 

R0 = ~R1

 

R0 = ~12345678.9

 

R0 = 0000_0000_1011_1100_0110_0001_0100_1110(12345679)
R0 = 1111_1111_0100_0011_1001_1110_1011_0001 (-12345681.0)

 

The operand is a Real memory locations.

 

When the Real value in R1 is loaded into the math stack it will be demoted to a 32-bit 2's complement value which will ignore the fractional portion of the Real value.

 

The result is placed in a Real memory location.

 

 


See Also:

Add

Subtract

Multiply

Divide


Modulus / Remainder

Raise to a Power


Less Than

Less than or Equal To

 

Equal To

Not Equal To

 

Greater Than

Greater Than or Equal To


Logical AND

Logical OR


Bit-wise AND

Bit-wise OR

Bit-wise XOR


Shift Left

Shift Right

Unsigned Shift Right

 

Negate

Bit-wise Invert

Logical NOT

 


Related Topics:

MATH - Calculate Expression