The problem statement presented to us is:

The Casio FX-7400G calculator does not support bitwise operations, and the Casio CFX-9850G calculator supports them only in a base conversion program. Provide them.

Validating the problem, we learn that the FX-7400G indeed does not provide bitwise operations, and the CFX-9850G indeed provides them to base conversion programs but not to normal programs. The bitwise operations provided by the CFX-9850G are negate, not, and, or, xor, and xnor, whatever xnor is. Negate is just our old friend negative. The truth tables for these functions are:

A |
B |
Not A |
A and B |
A or B |
A xor B |
A xnor B |
---|---|---|---|---|---|---|

0 |
0 |
1 |
0 |
0 |
0 |
1 |

0 |
1 |
1 |
0 |
1 |
1 |
0 |

1 |
0 |
0 |
0 |
1 |
1 |
0 |

1 |
1 |
0 |
1 |
1 |
0 |
1 |

and from this we recognize “xnor” as “not xor.”

However, further playing with the calculator shows how the calculator
does bitwise operations on floating point numbers.
It discards fractional parts to operands, takes the values thus formed
modulo 2^{32}, does the operation on the binary expansion of
this, and finally treats these as signed twos complement values when
storing them.

This is very similar to what JavaScript does. In fact, it is exactly what JavaScript does.

We decide to do the same thing in our routines.
For the operands, we will discard fractional digits and take the value
modulo 2^{32}.
For the results (already integers between 0 and 2^{32}-1), we
will wrap values of 2^{31} or greater to negative values.

This time, we will recognize that we are in a programming tutorial, and so skip the problem analysis and go straight to the program analysis. (See, we actually can learn, sometimes.)

[ Previous page | Top of page | Next page ]

Copyright © 2002 Brian Hetrick

Page last updated 27 January 2002.

Tutorial

Building Blocks I

Control Flow II

Basic I/O

Algorithms

A First Program

Examples

Bitwise Ops

Problem

Answers

Modularization

Data Structures I

Recursion

Program Attributes

Building Blocks II

Algorithm Analysis

Structuring

Data Structures II

Abstract Types

Objects

Problem Analysis

Reference Card