PIC32 Logic

Logic

abs
int
lshift
rshift
and
or
xor
not
cpl

 

abs()
abs(<expression>)
a=abs(-10)

Returns the absolute value of an expression, i.e. the positive value. In this example ‘a’ will contain 10.

int()
int(<expression>)
a=int(12.6)

Returns the integer value (left hand side of the decimal point) of a floating point expression. Note that due to automatic conversion, in the above example, as ‘a’ is an integer variable this will be converted to an integer anyway.

lshift()
lshift(y,z)
a%=lshift(1,4)

Bitwise shift to the left. This will shift the bits in value ‘y’ by the number given in z. In the example given the result in a& would be 16 (0x10).

rshift()
rshift(y,z)
a%=rshift(0x100,4)

Bitwise shift to the right. This will shift the bits in value ‘y’ by the number given in z. In the example given the result would be 16. To explain:

0x100     = 0001 0000 0000
16(0x10) = 0000 0001 0000

Number of bits shifted to the right is highlighted.

and()
and(y,z)
a%=and(0xff,3)

This is a bitwise logical and that will return the result of and’ing ‘y’ and ‘z’.  The result in this example would be 3.

or()
or(y,z)
a%=or(0xf0,3)

This is a bitwise logical or that will return the result of or’ing ‘y’ and ‘z’. The result in this example will be 0xf3

xor()
xor(y,z)
a%=xor(0xf0,0xf3)

This is a bitwise logical exclusive or that will return the result of exclusive or’ing ‘y’ and ‘z’. The result in this example will be 0x3

not()
not(<expression>)
a=not(1)
b=not(0)
c=not(77.4)

This is the LOGICAL not and so will return 1 if there is a 0 value and a 0 if there 1 value. So the result of ‘b’ is 1 and the result of ‘a’ and ‘c’ is 0.

cpl()
cpl(<expression>)
a%=cpl(0)
b%=cpl(3)

This is a bitwise complement of the given expression in an integer (32bit) field. The results of ‘a%’ are:

0000 0000 0000 0000 > 1111 1111 1111 1111 which is 0xffffffff

And the results of ‘b%’:

0000 0000 0000 0011 > 1111 1111 1111 1100 which is 0xfffffffc