AND/OR/XOR on non-16C calcs
03-16-2019, 06:06 PM
Post: #1
 Matt Agajanian Senior Member Posts: 458 Joined: Dec 2013
AND/OR/XOR on non-16C calcs
Hi all.

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

Thanks
03-16-2019, 07:17 PM (This post was last modified: 03-16-2019 07:21 PM by Dieter.)
Post: #2
 Dieter Senior Member Posts: 2,401 Joined: Dec 2013
RE: AND/OR/XOR on non-16C calcs
(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, 09:38 PM
Post: #3
 Matt Agajanian Senior Member Posts: 458 Joined: Dec 2013
RE: AND/OR/XOR on non-16C calcs
(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, 10:27 PM
Post: #4
 grsbanks Senior Member Posts: 736 Joined: Jan 2017
RE: AND/OR/XOR on non-16C calcs
(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
03-17-2019, 12:08 AM
Post: #5
 Matt Agajanian Senior Member Posts: 458 Joined: Dec 2013
RE: AND/OR/XOR on non-16C calcs
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.
03-17-2019, 03:18 AM
Post: #6
 Garth Wilson Senior Member Posts: 346 Joined: Dec 2013
RE: AND/OR/XOR on non-16C calcs
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-17-2019, 09:16 AM
Post: #7
 Dieter Senior Member Posts: 2,401 Joined: Dec 2013
RE: AND/OR/XOR on non-16C calcs
(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
03-17-2019, 03:35 PM
Post: #8
 Matt Agajanian Senior Member Posts: 458 Joined: Dec 2013
RE: AND/OR/XOR on non-16C calcs
Thanks for sharing more ‘tricks up your sleeve!’

They’ll come in handy.
03-17-2019, 04:57 PM (This post was last modified: 03-17-2019 04:58 PM by Dieter.)
Post: #9
 Dieter Senior Member Posts: 2,401 Joined: Dec 2013
RE: AND/OR/XOR on non-16C calcs
(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
03-17-2019, 05:52 PM
Post: #10
 Matt Agajanian Senior Member Posts: 458 Joined: Dec 2013
RE: AND/OR/XOR on non-16C calcs
Thanks again. Those HP Notes issues are absolutely essential!
03-17-2019, 11:13 PM
Post: #11
 Valentin Albillo Senior Member Posts: 315 Joined: Feb 2015
RE: AND/OR/XOR on non-16C calcs
(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.

V.
.
03-18-2019, 12:19 AM
Post: #12
 Matt Agajanian Senior Member Posts: 458 Joined: Dec 2013
RE: AND/OR/XOR on non-16C calcs
I’ll look for it at ABE Books and of course Amazon. Thanks for the tip.
03-18-2019, 01:58 AM
Post: #13
 rprosperi Senior Member Posts: 3,208 Joined: Dec 2013
RE: AND/OR/XOR on non-16C calcs
(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.

--Bob Prosperi
03-19-2019, 12:50 PM
Post: #14
 rprosperi Senior Member Posts: 3,208 Joined: Dec 2013
RE: AND/OR/XOR on non-16C calcs
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.

--Bob Prosperi
03-20-2019, 01:51 AM
Post: #15
 rprosperi Senior Member Posts: 3,208 Joined: Dec 2013
RE: AND/OR/XOR on non-16C calcs
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.

--Bob Prosperi
Today, 03:20 PM
Post: #16
 David Hayden Member Posts: 237 Joined: Dec 2013
RE: AND/OR/XOR on non-16C calcs
"Calculator Tips and Routines" is also available on TOS and the HHC 2017 thumb drive.
 « Next Oldest | Next Newest »

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