Page 1 of 1

Reading individual bits

Posted: Wed Jul 27, 2011 5:41 pm
by Dave S
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.

Re: Reading individual bits

Posted: Wed Jul 27, 2011 7:21 pm
by medelec35
Hi Dave,
If reading from a variable e.g variable is = 23
I believe you can test each individual bit by the following method:
Bit testing of a byte.jpg
Bit testing of a byte.jpg (52.4 KiB) Viewed 6481 times
So if you wanted to test bit 3 use:
(Variable & (1<<3))
Etc.

Hope this Helps

Martin

Re: Reading individual bits

Posted: Wed Jul 27, 2011 8:40 pm
by Dave S
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.

Re: Reading individual bits

Posted: Thu Jul 28, 2011 7:43 am
by medelec35
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

Code: Select all

        16  8  4  2  1  
23 =    1   0  1  1  1
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

Re: Reading individual bits

Posted: Thu Jul 28, 2011 9:01 am
by Dave S
Thanks Martin,

There seems to be a lot of information on line. Problem is in finding it!

Dave.

Re: Reading individual bits

Posted: Fri Aug 05, 2011 12:22 am
by medelec35
Dave S wrote:Thanks Martin,

There seems to be a lot of information on line. Problem is in finding it!

Dave.
I couldn't agree more, for that reason I posted this:
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

Re: Reading individual bits

Posted: Mon Aug 08, 2011 8:26 am
by Dave S
medelec35 wrote:
Dave S wrote:Thanks Martin,

There seems to be a lot of information on line. Problem is in finding it!

Dave.
I couldn't agree more, for that reason I posted this:
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
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?
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.

Re: Reading individual bits

Posted: Mon Aug 08, 2011 8:47 am
by medelec35
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.
Have you looked here?:
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.

Re: Reading individual bits

Posted: Thu Aug 11, 2011 7:58 pm
by Dave S
I saw the flowkit document thanks. By tutorials do you mean the video's?

The "in circuit debugging" one just shows the simulator :roll:

Dave