Hi all,
Is there any way to read individual bits from a Flowcode variable without resorting to C code please?
Something like a decision block with: "If Variable,3 = 1" with yes or no outputs.
I can put : "If variable = 23" and it works fine but I need to test each of the 8 bits and act on the value of each one.
You can read in individual bits from ports.............
Thanks,
Dave.
Reading individual bits
Moderator: Benj
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Reading individual bits
Hi Dave,
If reading from a variable e.g variable is = 23
I believe you can test each individual bit by the following method: So if you wanted to test bit 3 use:
(Variable & (1<<3))
Etc.
Hope this Helps
Martin
If reading from a variable e.g variable is = 23
I believe you can test each individual bit by the following method: So if you wanted to test bit 3 use:
(Variable & (1<<3))
Etc.
Hope this Helps
Martin
Martin
-
- Posts: 39
- Joined: Tue Jun 07, 2011 12:37 pm
- Has thanked: 12 times
- Been thanked: 5 times
- Contact:
Re: Reading individual bits
Thanks Martin that's very useful. I'll try it out first thing in the morning.
These statements appear to be derived from C? How do you find out what you can put in a decision box and what has to go in a C box?
I find the Flowcode help files very limited. Is there a document somewhere that details all of the syntax etc. for each function?
Thanks again for you help.
Dave.
These statements appear to be derived from C? How do you find out what you can put in a decision box and what has to go in a C box?
I find the Flowcode help files very limited. Is there a document somewhere that details all of the syntax etc. for each function?
Thanks again for you help.
Dave.
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Reading individual bits
Hi Dave.
(Variable & (1<<3)) may be a command that's found in C programs, but we are not not using any C boxes as such.
This type of calculation can be also used in the normal decision branches and non C calculation boxes.
Since this is the case it should work with the Flowcode simulator.
To be honest I'm not an expert with these type of commands but the way It works is ANDing with the bit you want to compare with and masking out all the other bits
Bit 3 = 2 to the power of 3 = 8
(2y3)
so its ANDing 23 with 8
Note: the << just means shift bits to the left = double the previous value. Likewise >> is shift bits to the right = half the previous value.
1<<1 = 1y2 = 2
1<<2 = 2y2 = 4
1<<3 = 3y2 = 8
1<<4 = 4y2 = 16
1<<5 = 5y2 = 32 etc.
You will only get a 1 if bit 3 is 1 since all other bits are masked off.
As you can See, Bit 3 is 0, so the result is 0 so bit 3 of 23 is off
Take a look at this great article on Simple Masking Technique:
http://www.matrixmultimedia.com/article.php?a=366
Which is where I remembered the information from.
These articles do come in very handy for learning with Flowcode.
Martin
(Variable & (1<<3)) may be a command that's found in C programs, but we are not not using any C boxes as such.
This type of calculation can be also used in the normal decision branches and non C calculation boxes.
Since this is the case it should work with the Flowcode simulator.
To be honest I'm not an expert with these type of commands but the way It works is ANDing with the bit you want to compare with and masking out all the other bits
Bit 3 = 2 to the power of 3 = 8
(2y3)
so its ANDing 23 with 8
Code: Select all
16 8 4 2 1
23 = 1 0 1 1 1
1<<1 = 1y2 = 2
1<<2 = 2y2 = 4
1<<3 = 3y2 = 8
1<<4 = 4y2 = 16
1<<5 = 5y2 = 32 etc.
You will only get a 1 if bit 3 is 1 since all other bits are masked off.
As you can See, Bit 3 is 0, so the result is 0 so bit 3 of 23 is off
Take a look at this great article on Simple Masking Technique:
http://www.matrixmultimedia.com/article.php?a=366
Which is where I remembered the information from.
These articles do come in very handy for learning with Flowcode.
Martin
Martin
-
- Posts: 39
- Joined: Tue Jun 07, 2011 12:37 pm
- Has thanked: 12 times
- Been thanked: 5 times
- Contact:
Re: Reading individual bits
Thanks Martin,
There seems to be a lot of information on line. Problem is in finding it!
Dave.
There seems to be a lot of information on line. Problem is in finding it!
Dave.
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Reading individual bits
I couldn't agree more, for that reason I posted this:Dave S wrote:Thanks Martin,
There seems to be a lot of information on line. Problem is in finding it!
Dave.
http://www.matrixmultimedia.com/mmforum ... 451#p26400
Which is asking for more information on different types of bit/byte manipulation to be added to that article (with examples given)
Perhaps even a contents or index like a book will help?
Martin
Martin
-
- Posts: 39
- Joined: Tue Jun 07, 2011 12:37 pm
- Has thanked: 12 times
- Been thanked: 5 times
- Contact:
Re: Reading individual bits
I've been using Flowcode for about a month now after previously using asm. Flowcode is an amazing program let down by its lack of documentation. I have learned a lot in a month, mainly from ploughing through examples and asking questions on here to helpful people like yourself. Why can't we just have a manual?medelec35 wrote:I couldn't agree more, for that reason I posted this:Dave S wrote:Thanks Martin,
There seems to be a lot of information on line. Problem is in finding it!
Dave.
http://www.matrixmultimedia.com/mmforum ... 451#p26400
Which is asking for more information on different types of bit/byte manipulation to be added to that article (with examples given)
Perhaps even a contents or index like a book will help?
Martin
Another example, I've just bought a Flowkit. It came with a nice glossy booklet telling me about Eblocks in many different languages. You have to search on the web for instructions for Flowkit.
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Reading individual bits
Have you looked here?:Dave S wrote: Another example, I've just bought a Flowkit. It came with a nice glossy booklet telling me about Eblocks in many different languages. You have to search on the web for instructions for Flowkit.
http://www.matrixmultimedia.com/mmforum ... =26&t=7138
One thing that’s got better is the tutorials.
Have a look in the leaning centre:
http://www.matrixmultimedia.com/lc_index.php
Martin.
Martin
-
- Posts: 39
- Joined: Tue Jun 07, 2011 12:37 pm
- Has thanked: 12 times
- Been thanked: 5 times
- Contact:
Re: Reading individual bits
I saw the flowkit document thanks. By tutorials do you mean the video's?
The "in circuit debugging" one just shows the simulator
Dave
The "in circuit debugging" one just shows the simulator
Dave