HP Forums

Full Version: AND/OR/XOR on non-16C calcs
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all.

Is there a way to program conditionals (and perhaps flag tests) that simulate and, or, and xor tests?

Thanks
(03-16-2019 06:06 PM)Matt Agajanian Wrote: [ -> ]Is there a way to program conditionals (and perhaps flag tests) that simulate and, or, and xor tests?

I am not sure if I understand what you are trying to do. An "OR"-test can be done on classic RPN calculators by having the inverse of the first condition followed by the second one.

Examples:

is flag 1 or flag 2 set?

FC? 01
FS? 02

is x=0 or x>0?

X≠0?
X>0?

But since you mention the 16C: how can you do this there?
A bitwise OR is not a logical OR.

Dieter
(03-16-2019 07:17 PM)Dieter Wrote: [ -> ]
(03-16-2019 06:06 PM)Matt Agajanian Wrote: [ -> ]Is there a way to program conditionals (and perhaps flag tests) that simulate and, or, and xor tests?

I am not sure if I understand what you are trying to do. An "OR"-test can be done on classic RPN calculators by having the inverse of the first condition followed by the second one.

Examples:

is flag 1 or flag 2 set?

FC? 01
FS? 02

is x=0 or x>0?

X≠0?
X>0?

But since you mention the 16C: how can you do this there?
A bitwise OR is not a logical OR.

Dieter

Hi Dieter (and all), I mention the 16C as a reference point/example of Or/Xor/And as test types regardless of programmable.

Okay. thanks for the Or tests. How do I structure an AND test?
(03-16-2019 09:38 PM)Matt Agajanian Wrote: [ -> ]Okay. thanks for the Or tests. How do I structure an AND test?

In much the same way as you would an OR test because:

NOT(A AND B) = NOT(A) OR NOT(B)

So, are both flags 1 and 2 set?

FS? 1
FC? 2
DO_IF_NOT_BOTH_SET
DO_IF_BOTH_SET
Thanks Dieter & gsbanks. These help me incorporate the some new conditionals to my programming library.

If other users have tricks & tips, I’d like to see what other variations I could add to my library.
If you want bitwise operations, the HP-41 Advantage module has AND, OR, XOR, NOT, BIT?, ROTXY (rotate the number in Y to the right by the number of bits specified in X, and rotating right (32-x) bits is equivalent to rotating left x bits).

Håkan Thörngren's 'Ladybug' module gives the 41 a new customizable binary integer mode, with most HP-16C capabilities, and stack items up to 64-bit (the last 8 bits being kept in a buffer). It does arithmetic, bitwise, and logical operations in bases 2, 8, 10, and 16. (Everything is in the .zip file at http://hpmuseum.org/forum/thread-7545.html .)
(03-16-2019 10:27 PM)grsbanks Wrote: [ -> ]NOT(A AND B) = NOT(A) OR NOT(B)

So, are both flags 1 and 2 set?

FS? 1
FC? 2
DO_IF_NOT_BOTH_SET
DO_IF_BOTH_SET

You may add an always-false test to get the usual "do if true" rule:

FS? 01
FC? 02
FS? 54
DO IF BOTH SET

Or, if you know that x cannot be negative at this point:

FS? 01
FC? 02
X<0?
DO IF BOTH SET

Dieter
Thanks for sharing more ‘tricks up your sleeve!’

They’ll come in handy.
(03-17-2019 03:35 PM)Matt Agajanian Wrote: [ -> ]Thanks for sharing more ‘tricks up your sleeve!’

If you like this kind of stuff youshould take a look at HP Key Notes V1N3 (Octobher 1977) where this and similar topics are discussed. Please note that this article refers to the HP67/97 where testing flag 2 or flag 3 clears this flag, i.e. it works like a FS?C 2 and FS?C 3.

Dieter
Thanks again. Those HP Notes issues are absolutely essential!
(03-17-2019 05:52 PM)Matt Agajanian Wrote: [ -> ]Thanks again. Those HP Notes issues are absolutely essential!

For bazillions of very short, highly-efficient RPN mini-routines (including a few by me) that do all kinds of things like those you're asking for in this thread, one essential source would be the book "Calculator Tips and Routines" by John Dearing.

I do own a copy and though it's several decades old I still use it frequently to this very day. Highly recommended. Big Grin

V.
.
I’ll look for it at ABE Books and of course Amazon. Thanks for the tip.
(03-18-2019 12:19 AM)Matt Agajanian Wrote: [ -> ]I’ll look for it at ABE Books and of course Amazon. Thanks for the tip.

Matt - This book is available at TOS, in PDF. Of course a real copy is always preferred, but at least this version can be used until you can locate an original copy.

And I agree with Valentin - this book contains a LOT of useful small RPN tips, for all kinds of uses. Many times in the distant past I had concluded I had read it fully and no need to look again, but when eventually going back, found things I did not recall were there. The kind of book that each time you pick it up, you discover new things. You will enjoy it.
There is an auction on eBay now for an HP-41C with some accessories, including what appears to be a nice copy of the "Calculator Tips and Routines" book here.

I am not suggesting that a copy of this is book is worth $120.00 for everyone, however based on your collecting preferences and priorities, it is possible it may be worth it to someone, and that person would also get an HP-41C & accessories for free. The 41C appears to be working, with tall keys, gold balls, s/n 2026A.... so it's actually not a bad deal at all, again depending on your needs. Might make a nice 41CL host.

Just an FYI, I've no connection with the seller.
Amazingly, here is another copy of the book:

https://www.ebay.com/itm/HP41-Calculator...4170467331

And this time much cheaper, but no free 41C included.
"Calculator Tips and Routines" is also available on TOS and the HHC 2017 thumb drive.
Reference URL's