Post Reply 
AND/OR/XOR on non-16C calcs
03-16-2019, 06:06 PM
Post: #1
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
Find all posts by this user
Quote this message in a reply
03-16-2019, 07:17 PM (This post was last modified: 03-16-2019 07:21 PM by Dieter.)
Post: #2
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
Find all posts by this user
Quote this message in a reply
03-16-2019, 09:38 PM
Post: #3
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?
Find all posts by this user
Quote this message in a reply
03-16-2019, 10:27 PM
Post: #4
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
Find all posts by this user
Quote this message in a reply
03-17-2019, 12:08 AM
Post: #5
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.
Find all posts by this user
Quote this message in a reply
03-17-2019, 03:18 AM
Post: #6
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 .)

http://WilsonMinesCo.com (Lots of HP-41 links at the bottom of the links page, http://wilsonminesco.com/links.html )
Visit this user's website Find all posts by this user
Quote this message in a reply
03-17-2019, 09:16 AM
Post: #7
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
Find all posts by this user
Quote this message in a reply
03-17-2019, 03:35 PM
Post: #8
RE: AND/OR/XOR on non-16C calcs
Thanks for sharing more ‘tricks up your sleeve!’

They’ll come in handy.
Find all posts by this user
Quote this message in a reply
03-17-2019, 04:57 PM (This post was last modified: 03-17-2019 04:58 PM by Dieter.)
Post: #9
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
Find all posts by this user
Quote this message in a reply
03-17-2019, 05:52 PM
Post: #10
RE: AND/OR/XOR on non-16C calcs
Thanks again. Those HP Notes issues are absolutely essential!
Find all posts by this user
Quote this message in a reply
03-17-2019, 11:13 PM
Post: #11
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. Big Grin

V.
.

  
Find All My HP-related Materials here:  Valentin Albillo's HP Collection
 
Visit this user's website Find all posts by this user
Quote this message in a reply
03-18-2019, 12:19 AM
Post: #12
RE: AND/OR/XOR on non-16C calcs
I’ll look for it at ABE Books and of course Amazon. Thanks for the tip.
Find all posts by this user
Quote this message in a reply
03-18-2019, 01:58 AM
Post: #13
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
Find all posts by this user
Quote this message in a reply
03-19-2019, 12:50 PM
Post: #14
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
Find all posts by this user
Quote this message in a reply
03-20-2019, 01:51 AM
Post: #15
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
Find all posts by this user
Quote this message in a reply
03-24-2019, 03:20 PM
Post: #16
RE: AND/OR/XOR on non-16C calcs
"Calculator Tips and Routines" is also available on TOS and the HHC 2017 thumb drive.
Find all posts by this user
Quote this message in a reply
Post Reply 




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