Variable Bit Testing

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
JANUARY1
Posts: 15
Joined: Sun Jun 03, 2012 1:05 pm
Location: KENDAL
Been thanked: 2 times
Contact:

Variable Bit Testing

Post by JANUARY1 »

Hi could you tell me how to do bit testing on a variable not a port MANY THANKS :mrgreen:
ON FLOWCODE 5 PROF
and can the interupt be made faster than 15hz on 18f2550 and 16f737

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: VARIABLE BIT TESTING

Post by Benj »

Hello,

You can do something like this.

Say the variable is a byte called bytevar you can check the state of bit 0 by doing this inside a decision icon.

Code: Select all

bytevar & 0x01
if you want to check bit 1 then it becomes

Code: Select all

bytevar & 0x02
bit2 = 0x04
bit3 = 0x08
bit4 = 0x10
bit5 = 0x20
bit6 = 0x40
bit7 = 0x80

or you can do it pragmatically using a second variable bitvar to store the bit location 0 to 7.

Code: Select all

bytevar & (0x01 << bitvar)
If you need to store the value of the bit rather then simply acting on it then you can do this in a calculation icon. Note that this will simply copy the bit value across.

Code: Select all

bitstate = bytevar & (0x01 << bitvar)
If instead you need the bit value to be equal to 0 or 1 then you can instead do this.

Code: Select all

bitstate = (bytevar >> bitvar) & 0x01

Post Reply