Bit extraction in flowcode

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
Roy Johnston
Flowcode V4 User
Posts: 220
Joined: Mon Aug 24, 2009 8:38 am
Has thanked: 2 times
Been thanked: 34 times

Bit extraction in flowcode

Post by Roy Johnston »

in visual basic i use the followin formula to extact the single bits out of a Byte, how do i do this in flowcode

Dim x As Long
x = bDataIn(1)
Me.x0 = (x And 1)
Me.x1 = (x And 2) / 2
Me.x2 = (x And 4) / 4
Me.x3 = (x And 8) / 8
Me.x4 = (x And 16) / 16
Me.x5 = (x And 32) / 32
Me.x6 = (x And 64) / 64
Me.x7 = (x And 128) / 128

thks in advance

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: Bit extraction in flowcode

Post by medelec35 »

Hello Roy.
To do this you could use an array. To use an eight index array just drag a calculation box onto main of flowchart,
double click on it, then Click 'variables.' then Add New Variable...'
In the small window enter byte variable called: Number_Bit[8]
Or a variable name of your choice.
Also add another byte variable called Number then give it a value in a calculation box.

Then in a calculation box, enter the following :
Number_Bit[0] = (Number AND 1)
Number_Bit[1] = (Number AND 2)/2
Number_Bit[2] = (Number AND 4)/4
etc.
Or
Number_Bit[0] = (Number AND 1)
Number_Bit[1] = (Number AND 2)>>1
Number_Bit[2] = (Number AND 4)>>2

Or of course with your variables: Me[8] plus x of course

Me[0] = (x AND 1)
Me[1]= (x AND 2)/2
etc
not much different from VB at all!
Hope this helps
Martin

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: Bit extraction in flowcode

Post by medelec35 »

Screen Shot:
Bit extraction.jpg
Bit extraction.jpg (104.08 KiB) Viewed 2370 times
Martin

Post Reply