Saturday, April 25, 2020

HP 42S/DM42/Free 42: Advanced Boolean Functions

HP 42S/DM42/Free 42: Advanced Boolean Functions

Introduction

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

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 )

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 )

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

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

Eddie

All original content copyright, © 2011-2020.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.

Spotlight: Akron Brass FireCalc Pocket Computer

Spotlight: Akron Brass FireCalc Pocket Computer Welcome to a special Monday Edition of Eddie’s Math and Calculator blog. Thi...