Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 08:17 07 Jul 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Testing for Flags.

     Page 2 of 2    
Author Message
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 11:46am 02 Jul 2016
Copy link to clipboard 
Print this post

  matherp said   Here are a range of functions and subroutines that allow a program to maintain up to 32 single bit flags. These are stored in a "hidden" bit of memory. The use of the functions "flag" which returns true if the flag is set and "notflag" which returns true if the flag is clear makes the test for combinations extremely simple. By setting constants to name the flags you can then make the code very easy to read. It is probably good practice to clear all flags at the top of the program to get them all into a known state - don't assume they will start off clear.

[/quote]

Thanks Peter,

They look quite useful.

Thinking (Over Thinking?), this over a fair bit, and there are situations where an individual flag is of significance, and others where a set of flags is of primary concern.

Considering 1111011010111, where those bits in bold are to be considered.
The individual Flags, or "Bits", could be all stored & addressed by name to keep the code readable.

But if they could also be addressed as a group, that might be useful too.

If a Function could be called that returned the 1101, I think that could be handy in some instances.

[Code]
CFunction rflag 'Return the value of a set of flags, Position(0-31), Number of Bits(1-31)
[/code]

So in my above example,

if the first 13 flags were set as 1111011010111

FlagGroup=rflag(4,4) 'Or (5,4) depending on how the bits are actually numbered
Print Bin$(FlagGroup)
1101

Would return the 5th thru to the 8th bit.
I'm assuming that the way they are stored in the location would allow them to be returned in that manner.

In my case, where bits 3, 2 & 1 are Panel Threshold Met, Solar Threshold Met & Solar Minimum met, it could become:-

ThresholdsMet=rflag(4,4).

Not sure if this is a good suggestion or not?
I do have a tendency to think out loud & throw thoughts out in print.

Maybe an alternative would be to test for a pattern of n bits from a particular location & just return either true of false?

ThresholdsMet=tflags(&b1101,4,4), would return "1".


Cheers

Phil.
 
     Page 2 of 2    
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025