Post Reply 
HP 35s Logic Operator AND
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
 45 = 00101101 bin
--------------
AND = 00101001 bin
    =       41 dec

(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
A002 FS? 1
A003 GTO A005
A004 GTO A007
A005 FS? 2
A006 L.R.
A007 ...

Or, with just one jump:
Code:
A001 LBL A
A002 CF 0
A003 FS? 1
A004 FS? 0
A005 GTO A008
A006 FS? 2
A007 L.R.
A008 ...

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
A002 X>0?
A003 GTO A008 -----+
A004 e^x           |
A005 2             |
A006 x             |
A007 GTO A010 --+  |
A008 LN  <------|--+ 
A009 x²         |
A010 ... <------+

Dieter
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
HP 35s Logic Operator AND - MNH - 06-19-2016, 06:37 AM
RE: HP 35s Logic Operator AND - Dieter - 06-19-2016, 02:28 PM
RE: HP 35s Logic Operator AND - Dieter - 06-19-2016 01:40 PM
RE: HP 35s Logic Operator AND - MNH - 06-19-2016, 11:37 PM



User(s) browsing this thread: 1 Guest(s)