HP 35s Logic Operator AND
|
06-19-2016, 06:37 AM
Post: #1
|
|||
|
|||
HP 35s Logic Operator AND
I'm burning some serious midnight oil here in Florida. I just started programming the HP 35s this month. How would I use the logic operator AND to test two flags? Also, in the absence of IF-ELSE and IF-THEN-ELSE statements, is there a better alternative than branching to subroutines? Thanks, and happy Father's Day to all the dads!
|
|||
06-19-2016, 07:18 AM
Post: #2
|
|||
|
|||
RE: HP 35s Logic Operator AND
(06-19-2016 06:37 AM)MNH Wrote: I'm burning some serious midnight oil here in Florida. I just started programming the HP 35s this month. How would I use the logic operator AND to test two flags?In program mode, use something like this: Code:
|
|||
06-19-2016, 01:40 PM
(This post was last modified: 06-19-2016 01:54 PM by Dieter.)
Post: #3
|
|||
|
|||
RE: HP 35s Logic Operator AND
(06-19-2016 06:37 AM)MNH Wrote: I'm burning some serious midnight oil here in Florida. I just started programming the HP 35s this month. The 35s AND is a bitwise AND, not a logical AND. So 123 AND 45 is 41: Code: 123 = 01111011 bin (06-19-2016 06:37 AM)MNH Wrote: How would I use the logic operator AND to test two flags? As pointed out, you cannot use AND or OR or NOT for logical operations. But in the olden days the good RPN programmer knew how to handle this. You can combine two or more tests to simulate some logical operations. If you have one test A directly followed by another one B, this combination simulates a (NOT A) OR B. For instance X=0? FS? 1 is equivalent to a test whether X does not equal zero OR flag 1 is set. An AND is somewhat trickier. Usually you would write the program differently to avoid this and use an OR test like the one above instead. Testing if both of two flags are set usually requires a FC? command which the 35s lacks. But since it has line number addressing it can be done this way. The example does a linear regression if both flag 1 and 2 are set: Code: A001 LBL A Or, with just one jump: Code: A001 LBL A The flag 0 test can be anything that tests false. So if you know that at this point the value in X cannot be negative you could also use "X<0?" instead of "FS? 0" and remove the initial CF 0 line. (Note to HP67/97 users: two consecutive tests of flag 2 or 3 yield a FC? test since these two flags are cleared when tested.) Yes, this uses another trick on the same kind: Have a test followed by another one that tests false means that the first test is inverted. For more information on this take a look at the old forum, e.g. here. (06-19-2016 06:37 AM)MNH Wrote: Also, in the absence of IF-ELSE and IF-THEN-ELSE statements, is there a better alternative than branching to subroutines? Thanks, and happy Father's Day to all the dads! There is no need for subroutines. Simple GTOs will do. Example: if x>0 compute ln²(x), else compute 2 · ex Code: A001 LBL A Dieter |
|||
06-19-2016, 02:28 PM
(This post was last modified: 06-19-2016 02:34 PM by Dieter.)
Post: #4
|
|||
|
|||
RE: HP 35s Logic Operator AND
(06-19-2016 07:18 AM)Thomas Radtke Wrote: In program mode, use something like this: This looks a bit complicated. I assume you want to do something like this: Code: 0 Or even better, using the 35s NOT operator: Code: 0 This yields a 1 resp. –1 if both flags are set, and a 0 otherwise. So the next step after this is a simple X≠0? which actually tests whether both flags are set. Or you could also use an X=0? instead if you want to test if at least one flag is cleared. This method can be extended to many more logical combinations. The basic idea is: have the tests return a 0 if false or a 1 or -1 if true, and then combine their results with the 35s logic operators. Dieter |
|||
06-19-2016, 04:40 PM
Post: #5
|
|||
|
|||
RE: HP 35s Logic Operator AND | |||
06-19-2016, 11:37 PM
Post: #6
|
|||
|
|||
RE: HP 35s Logic Operator AND
Thank you Thomas and Dieter for your help!
|
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 3 Guest(s)