Programming "AND" of two flags in the non RPL machines - Printable Version +- HP Forums (https://archived.hpcalc.org/museumforum) +-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html) +--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html) +--- Thread: Programming "AND" of two flags in the non RPL machines (/thread-122564.html) Programming "AND" of two flags in the non RPL machines - Peter Niessen - 08-22-2007 Hi, how to program an "AND" of two flags? I can come up only with ```0 FS? 0 1 FS? 1 1 * X!=0? ``` Is there a better way? Thanks, Peter. Re: Programming "AND" of two flags in the non RPL machines - Paul Dale - 08-22-2007 Slightly smaller is: ```PI FS? 0 IP ; Integer part FS? 1 FP ; Fractional part x=0? ``` - Pauli Re: Programming "AND" of two flags in the non RPL machines - Valentin Albillo - 08-23-2007 Hi, Peter: Peter asked: "How to program an "AND" of two flags? I can come up only with [... (a 7-step solution) ...] Is there a better way? If your program is intended to run in an HP-41C/CV/CX, an HP42S, or some suitably compatible model or emulation, and you don't care for the status of flag 00 (or 01) after the test, I can come up with a 3-step solution, namely: ``` FC? 01 CF 00 FS? 00 ``` You can exchange flag 00 for flag 01 in the above solution if you can't afford clearing flag 00 but don't mind clearing flag 01 instead. Also, not only is my solution shorter, but significantly faster as well and the cherry on top is that it also preserves the whole RPN stack, LASTX included. Best regards from V. Edited: 23 Aug 2007, 9:10 a.m. after one or more responses were posted Re: Programming "AND" of two flags in the non RPL machines - Vincze - 08-23-2007 I guess I not understand something. What is flag checking? Re: Programming "AND" of two flags in the non RPL machines - Giancarlo (Italy) - 08-23-2007 Hi Vincze. If you question arises from the "FC" or "CF" acronyms, then they stand for "Flag Clear" and "Clear Flag" respectively. "Clearing" a flag basically means "unsetting" it (i.e., setting its value to "0"); "Setting" a flag, obviously, means the opposite ;-) "Flag checking" is just the checking for the flag status (set/clear). If you mean "what is this strange mess with flags?", then very synthetically: many functions and settings of HP calcs (at least of the most recent and powerful ones) are customizable by means of those "flag settings", which "set" the "operational environment" of the calc itself. Hope my humble explanation was not more confusing to you ;-) Best regards. Giancarlo Edited: 23 Aug 2007, 9:20 a.m. Re: Programming "AND" of two flags in the non RPL machines - Vincze - 08-23-2007 I guess I more interested in what is flag setting all about. I know of 15C, there is flag setting to enter complex mode. But on 35s, I not understand when book says flags 0 - 4 mean whatever you want them to mean. Is it like it store boolean value for later use? Re: Programming "AND" of two flags in the non RPL machines - Stefan Vorkoetter - 08-23-2007 Exactly. Flags are just boolean values. On the 35s, flags 0-4 happen to have their state displayed in the annunciator area, which makes them useful to visually indicate some sort of status. Some flags are also used to control settings of the calculator, such as setting flag 10 to inhibit equation evaluation. Stefan Re: Programming "AND" of two flags in the non RPL machines - Stefan Vorkoetter - 08-23-2007 Another solution that preserves the stack and LASTx uses a third flag. So if you're testing flags 0 and 1, the following will set flag 2 to the AND of flags 0 and 1, and then test the result: ```SF 2 FC? 0 CF 2 FC? 1 CF 2 FS? 2 ``` Likewise, the following does OR: ```CF 2 FS? 0 SF 2 FS? 1 SF 2 FS? 2 ``` Alternatively, if all you're interested in is branching somewhere if the AND is true, you could write: ```FC? 0 GTO N FC? 1 GTO N LBL A ...stuff to do if flags 0 and 1 are set LBL N ...stuff to do if one or both of flags 0 and 1 are not set ``` Stefan Re: Programming "AND" of two flags in the non RPL machines - Peter Niessen - 08-23-2007 Had one only FC? on the 3Xs machines... (where X=2,3,5). Thanks for these answers! Learnt something for today and should go home. Cheers, Peter.