Post Reply 
(35S) years, months and days between two dates
06-15-2016, 08:24 PM
Post: #7
RE: HP 35s: years, months and days between two dates
(06-15-2016 03:33 PM)ggauny@live.fr Wrote:  Because I'm a bit misunderstanding the "NAND" command which is too implemented in the WP34s, may I ask for an explication ?

NAND is a logical operator, the inverse of AND (NAND = NOT AND). It behaves this way:

0 NAND 0 = 1
0 NAND 1 = 1
1 NAND 0 = 1
1 NAND 1 = 0

So the result of the NAND operation is 0 if both arguments are 1, and 0 else.

The 35s does not use a logical NAND (which is what the 34s calculates in its regular real modes), but is uses a bitwise NAND. Here the two arguments are taken bit by bit, and the respective bit of the result is calculated according to the table above.

Now an even number has 0 as its last bit. So NANDing it with 1 means (look at the table) that the last bit of the result is 1. All other bits are NANDed with 0 which means that they are 1 in the result. Which accordingly is 11111.....1. For a signed integer this is the binary representation of -1.

An odd number hat 1 as its last bit. NANDing it with 1 means (look at the table again) that the last bit of the result is 0. All other bits are NANDed with 0 which means that they are 1 in the result. Which accordingly is 1111...0. For a signed integer this is the binary representation of -2.

In other words: x NAND 1 yields -1 if x is even, and -2 if x is odd. This property is used in the program.

You can also do this on the 34s. In normal real mode (DECM, H.d) NAND acts as a logical NAND, i.e. 0 is treated as 0 and any other number is the same as 1. The result is either 0 or 1, just as the table says. However, you can use the 35s method after switching to an integer mode: In Base-10 mode you will get the same results as the 35s. But on a 34s there are other ways to achieve the same result, e.g. 2 MOD INC X +/–.

All in all, this NAND method is just a small trick to show off a rarely used command in order to save one step or two. ;-)

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


Messages In This Thread
RE: HP 35s: years, months and days between two dates - Dieter - 06-15-2016 08:24 PM



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