Previous page Next page Navigation bar

Programs

Utility Programs

Boolean Operations

Summary Description

Program:

BOOLOP

Version:

1.0, 7 July 2002

Description:

This program performs all 16 possible boolean operations on two values.

Compatability:

Is compatible CFX-9850G

Compatible with CFX-9850G

Is compatible FX-7400G

Compatible with FX-7400G

Other programs
required:

None

Detailed Description

The Casio CFX-9850G calculator permits logical expressions (such as those in If statements) to use the Boolean operators and, or, and not. The Casio FX-7400G calculator, however, does not. Programs compatible with both calculators must therefore avoid the use of these operators. The BOOLOP program implements all possible Boolean operators on two values such that both calculators can use them.

The BOOLOP program takes two Boolean values — which are regarded as true or false as they are non-zero or zero — and an operation code, and computes the indicated operation on the two values. The operation code is a value between 0 and 15, inclusive, derived from the truth table of the desired operation. The operation code is the sum of the values indicated by the following table:

Operand 1

Operand 2

Operation code value

False

False

1 if True, 0 if False

False

True

2 if True, 0 if False

True

False

4 if True, 0 if False

True

True

8 if True, 0 if False

The operation code 0 always results in False; 15 always results in True; 8 results in the logical And of Operand 1 and Operand 2; 14 results in the logical Or of Operand 1 and Operand 2; 3 results in the logical Not of Operand 1; and 5 results in the logical Not of Operand 2. Operation codes that have fractional parts or that are not between 0 and 15, inclusive, are treated as 0.

This program is very similar to, but not identical to, the program of the same name presented in the Programming Tutorial. This program uses the linkage conventions described in the Linkage Conventions page.

Usage

Load the BOOLOP program into the calculator. Place the first operand into variable A, the second operand into variable B, and the operation code as described above into variable C. Invoke the BOOLOP program.

The BOOLOP program will place the result (0 indicating false, 1 indicating true) into variable D.

Program Source

The programs are available as a text file with .CAT contents, or may be entered as shown below. A semicolon (“;”) marks the beginning of a comment, which is not to be entered into the calculator. Remember that these programs are copyrighted; see the copyright issues page for limitations on redistribution.

Program BOOLOP (77 bytes):

; Program: BOOLOP
;
; Description:
;   Performs a specified logical operation on two logical operands.
;   The logical operands are regarded as true if they are non-zero, or
;   as false if they are zero. The logical operation is specified by
;   an operation code derived from the truth table for the operation,
;   as follows:
;
;   Op 1   Op 2   Result
;   False  False    a
;   False  True     b
;   True   False    c
;   True   True     d
;
;   The values a, b, c, and d must be 0 or 1 to indicate the result as
;   false (0) or true (1). The values are then combined into a binary
;   number with digits dcba. The value of the binary number is the
;   operation code.
;
; Formal parameters:
;   A: Operand 1
;   B: Operand 2
;   C: The operation code
;   D: The result [output]
;
; Calling sequence:
;   {Operand 1}->A
;   {Operand 2}->B
;   {Operation code}->C
;   Prog "BOOLOP"
;   D->{result}
;
; Implicit inputs:
;   None.
;
; Implicit outputs:
;   None.
;
; Side effects:
;   None.
;
; Symbols used:
;   -> is assignment arrow
;   <> is not equal to relational
;   => is conditional jump
;   / is division operator
 
C->D               ; Copy operation code into D
D<>Int D=>0->D     ; If operation code non-integral, set to 0
D<0=>0->D          ; If operation code is out of range,
D>15=>0->D         ;   set to 0
A<>0=>D/4->D       ; If operand 1 true, isolate range
B<>0=>D/2->D       ; If operand 2 true, isolate range
2Frac (Int D/2)->D ; Extract result

In addition to these two programs, the text file with .CAT contents contains two unit tests.

[ Previous page | Top of page | Next page ]

Previous page Top of page Next page Navigation bar

Copyright © 2002 Brian Hetrick
Page last updated 7 July 2002.

Brian’s Casio Calculator Corner

Home

Programs

Index

Linkage Conventions

Mathematics

Finance

Physics

Utility

Index

Save/Restore

Line Drawing

Boolean Operations

Bitwise Operations

Tutorial

Puzzles

Site Information

Your Privacy

Site Map

E-mail

Site Technical Data