HP Forums
AND/OR/XOR on non-16C calcs - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: General Forum (/forum-4.html)
+--- Thread: AND/OR/XOR on non-16C calcs (/thread-12629.html)



AND/OR/XOR on non-16C calcs - Matt Agajanian - 03-16-2019 06:06 PM

Hi all.

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

Thanks


RE: AND/OR/XOR on non-16C calcs - Dieter - 03-16-2019 07:17 PM

(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


RE: AND/OR/XOR on non-16C calcs - Matt Agajanian - 03-16-2019 09:38 PM

(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?


RE: AND/OR/XOR on non-16C calcs - grsbanks - 03-16-2019 10:27 PM

(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


RE: AND/OR/XOR on non-16C calcs - Matt Agajanian - 03-17-2019 12:08 AM

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.


RE: AND/OR/XOR on non-16C calcs - Garth Wilson - 03-17-2019 03:18 AM

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 .)


RE: AND/OR/XOR on non-16C calcs - Dieter - 03-17-2019 09:16 AM

(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


RE: AND/OR/XOR on non-16C calcs - Matt Agajanian - 03-17-2019 03:35 PM

Thanks for sharing more ‘tricks up your sleeve!’

They’ll come in handy.


RE: AND/OR/XOR on non-16C calcs - Dieter - 03-17-2019 04:57 PM

(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


RE: AND/OR/XOR on non-16C calcs - Matt Agajanian - 03-17-2019 05:52 PM

Thanks again. Those HP Notes issues are absolutely essential!


RE: AND/OR/XOR on non-16C calcs - Valentin Albillo - 03-17-2019 11:13 PM

(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.
.


RE: AND/OR/XOR on non-16C calcs - Matt Agajanian - 03-18-2019 12:19 AM

I’ll look for it at ABE Books and of course Amazon. Thanks for the tip.


RE: AND/OR/XOR on non-16C calcs - rprosperi - 03-18-2019 01:58 AM

(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.


RE: AND/OR/XOR on non-16C calcs - rprosperi - 03-19-2019 12:50 PM

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.


RE: AND/OR/XOR on non-16C calcs - rprosperi - 03-20-2019 01:51 AM

Amazingly, here is another copy of the book:

https://www.ebay.com/itm/HP41-Calculator-Tips-and-Routines/254170467331

And this time much cheaper, but no free 41C included.


RE: AND/OR/XOR on non-16C calcs - David Hayden - 03-24-2019 03:20 PM

"Calculator Tips and Routines" is also available on TOS and the HHC 2017 thumb drive.