Page 1 of 1

FlipFlop / Readbit / Change Bit

Posted: Tue Oct 20, 2015 5:38 pm
by MJU
You've asked for it! :D

If you've got still some space on your "to-do" whiteboard, here some more suggestions:

Flipflop(var) -> Changes the state of the variable from 0 -> 1 or 1 -> 0

Maybe not the best suggestion but if you need to do that often it could be a great help..

ReadBit(var,position,number of bits): returns the value of certain bits in a byte.
So Readbit("10010100",2,2) would return "10" (starting from LSB).
Would come in handy to read values in registers from components.

ChangeBit(var,position,value): changes the value of a bit in a certain position in a byte to a specified..
So ChangeBit(10000000,4,1) will change the byte into: 10001000 (even if it was already 1)

Maybe these are not the most difficult things to do in Flowcode, but if you want the "fast" in "fast prototyping", they may come in handy..
Most of these suggestions can be done with masking, but... just suggestions.. :D

Re: FlipFlop / Readbit / Change Bit

Posted: Wed Oct 21, 2015 3:13 pm
by Benj
Hello,

Some more great suggestions there.

The flip flop to invert bits can be done with a ~ operator. I think this should simulate but I suppose it could be a lot more obvious to a new user.

The other two functions sound ok though, i'll get them on the list.

Re: FlipFlop / Readbit / Change Bit

Posted: Wed Oct 21, 2015 5:50 pm
by MJU
Benj wrote: The flip flop to invert bits can be done with a ~ operator. I think this should simulate but I suppose it could be a lot more obvious to a new user.
Can you please give an example of how the "~" operator works?
I have never crossed it and can't find anything about it on the Wiki..

I've tried to use it in a flowchart and it isn't recognised in several ways.. :(

Re: FlipFlop / Readbit / Change Bit

Posted: Wed Oct 21, 2015 8:19 pm
by medelec35
To flip a bit of a variable,
I personally use

Code: Select all

variable = variable XOR BitToBeFlipped
e.g
With bits 0 to 7
to flip bit 1 I would use:

Code: Select all

variable = variable XOR 2
I thought
MJU wrote:ReadBit(var,position,number of bits): returns the value of certain bits in a byte.
&
MJU wrote:ChangeBit(var,position,value): changes the value of a bit in a certain position in a byte to a specified..
are both good ideas.