HP Forums
Advanced Boolean Functions - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: General Software Library (/forum-13.html)
+--- Thread: Advanced Boolean Functions (/thread-14888.html)



Advanced Boolean Functions - Eddie W. Shore - 04-25-2020 12:39 PM

The programs NOTBIT, NAND, NOR, and IMPL are four advanced Boolean functions that work on Binary Numbers. You designate a bit size, up to 35, on each of these functions. There is no signed bit in these programs. Results are stored in the Alpha Register while the decimal equivalent is stored in the X register.

HP 42S/DM42/Free 42 Program: NOTBIT
Code:

00 { 57-Byte Prgm }
01▸LBL "NOTBIT"
02 "BIT SIZE?"
03 PROMPT
04 STO 00
05 BINM
06 "BIN?"
07 PROMPT
08 STO 01
09 DECM
10 2
11 RCL 00
12 Y↑X
13 X<>Y
14 BASE-
15 1
16 BASE-
17 BINM
18 "NOT: "
19 ARCL ST X
20 AVIEW
21 EXITALL
22 .END.

Example:

NOT 11011, bit size: 8

Result:
NOT: 11100100

HP 42S/DM42/Free 42 Program: NAND

a NAND b = NOT ( a AND b )
Code:

00 { 67-Byte Prgm }
01▸LBL "NAND"
02 "BIT SIZE?"
03 PROMPT
04 STO 00
05 BINM
06 "BIN1?"
07 PROMPT
08 STO 01
09 "BIN2?"
10 PROMPT
11 STO 02
12 AND
13 DECM
14 2
15 RCL 00
16 Y↑X
17 X<>Y
18 BASE-
19 1
20 BASE-
21 BINM
22 "NAND: "
23 ARCL ST X
24 AVIEW
25 EXITALL
26 .END.

Example:

110011 NAND 111100, bit size: 8

Result:
NAND: 11001111

HP 42S/DM42/Free 42 Program: NOR

a NOR b = NOT ( a OR b )
Code:

00 { 64-Byte Prgm }
01▸LBL "NOR"
02 "BIT SIZE"
03 PROMPT
04 STO 00
05 BINM
06 "BIN1?"
07 PROMPT
08 STO 01
09 "BIN2?"
10 PROMPT
11 STO 02
12 OR
13 DECM
14 2
15 RCL 00
16 Y↑X
17 X<>Y
18 BASE-
19 1
20 BASE-
21 BINM
22 "NOR: "
23 ARCL ST X
24 AVIEW
25 EXITALL
26 .END.

Example:

110011 NOR 111100, bit size: 8

Result:
NOR: 11000000

HP 42S/DM42/Free 42 Program: IMPL

IMPL (Implication): a → b = (NOT a) OR b
Code:

00 { 66-Byte Prgm }
01▸LBL "IMPL"
02 "BIT SIZE?"
03 PROMPT
04 STO 00
05 BINM
06 "BIN1?"
07 PROMPT
08 STO 01
09 DECM
10 2
11 RCL 00
12 Y↑X
13 X<>Y
14 BASE-
15 1
16 BASE-
17 BINM
18 "BIN2?"
19 PROMPT
20 STO 02
21 OR
22 "A→B: "
23 ARCL ST X
24 AVIEW
25 EXITALL
26 .END.

Example:

110011 IMPL 111100, bit size: 8

Result:
IMPL: 11111100

You can download the raw files here:
https://drive.google.com/open?id=19u8tPcX4_-o0lwvjUc0KO4-WSmhnxpwe

Source:

John W. Harris and Horst Stocker Handbook of Mathematics and Computation Science Springer: New York, NY. 2006. ISBN 978-0-387-94746-4

Blog Link: http://edspi31415.blogspot.com/2020/04/hp-42sdm42free-42-advanced-boolean.html


RE: Advanced Boolean Functions - Nihotte(lma) - 04-25-2020 04:03 PM

(04-25-2020 12:39 PM)Eddie W. Shore Wrote:  The programs NOTBIT, NAND, NOR, and IMPL are four advanced Boolean functions that work on Binary Numbers. You designate a bit size, up to 35, on each of these functions. There is no signed bit in these programs. Results are stored in the Alpha Register while the decimal equivalent is stored in the X register.

Thanks Eddie W. Shore,

I'm interesting to know : are you writing some programmable robot or other compiler ?


RE: Advanced Boolean Functions - Eddie W. Shore - 04-25-2020 06:13 PM

Not at the moment.