Enter RPN

R47: Flags
Login

R47: Flags

What Are Flags For?

Flags are 1-bit variables: zero or one, on or off, yes or no, true or false. In the HP scheme emulated by the R47, we use the terms “clear” and “set” in programs, but the meanings are up to each case.

To save space, the R47 software uses system flags for all settings taking Boolean values.

There is a tiny run-time efficiency cost to access a single bit on most modern CPUs — accessing a whole word is actually faster — but at the same time, wasting all but 1 bit in a word can cause its own efficiency hit by blowing CPU caches. Which one ends up faster can depend on several factors, which is why seasoned software developers learn to benchmark alternative expressions rather than stake their reputation on overconfident predictions.

For user programs, you might guess that interpretation overhead would overwhelm any such consideration, but that ignores the fact that data types carry interpretation costs of their own. The R47 has special-casing for each data type all over the place in its numeric processing algorithms. Calling one of the 🟧 FLAG facilities may be measurably faster simply because it bypasses much of this interpretation overhead. Wasting 63 bits by abusing a short integer may not matter to your application in terms of RAM usage — much as a C++ or C23 programmer might not count the cost of using a bool variable — but the speed difference might matter.

Benchmark it!

Which Flags Exist?

There are over 100 flags currently defined by the R47.1

If you know what you’re looking for and have a fair idea of what it is called, I recommend opening up the Flags & Settings index card and doing a search. That will guide you to the exact name and where it is in the menus. (Many are in two or more locations!)

A more verbose version of this is available in PDF form which is useful when you have but vague ideas about the name of the thing you are seeking. You might not even know what a given flag controls, exactly, but that can be okay as long as a related term turns up the pointer you want.

Failing all those sources, this doc is the most verbose of the reference material covering this, but consequently less squarely on-target for our task here.

As your experience grows — both with the R47 in specific but also HP and RPN in general — you will have an increasing chance that trawling through the on-device menus will be enough to remind you of the name of a sought-after flag.

🟧 PREF CFLG
🟧 FLAG CF/SF SYS.FL

Vexillography: The History of Flags

The R47 is a spiritual descendant of the HP-42S from 1988. As I write this, it is nearly twice as far back to its introduction as from that point back to the HP 9100A, where the first RPN seeds germinated:

⟽ 1968-1988 ⟾ ⟽ 1988-present ⟾
box "⟽ 1968-1988 ⟾" fit thin fill 0xFFCA63
box same width previous.width*(2026-1988)/(1988-1968) "⟽ 1988-present ⟾" thin fill 0xC0E1FF

Digging back into this history might be instructive in thinking about how R47 flags work, but feel free to skip to the next section.

What we now call user flags first appeared in the HP-65, introduced in 1974. While there must have been internal flags to indicate conditions like “numeric overflow,” an HP-65 program could not test for this and cope, as was possible on the later HP-32S and HP-42S. The calculator simply stopped.

1981’s HP-11C shared this same limitation, but the HP-15C lifted it a year later. One of its extensions over the HP-11C was to increase the count of user flags from 2 to 8, but it also added two new system flags, one of which (flag 9) allowed it to signal an overflow condition to user programs.

And yet, the HP-16C was released that same year in the same family, where the closest it came to this was flag 5, “out-of-range.” While that might be close enough to the meaning of “overflow” in the HP-15C to serve the 16C’s differing design, it does show that HP was not prioritizing cross-model compatibility at that time.

I view the HP-32S as the closest HP ever came to a successor for the HP-11C, but on learning that it has a flag 5 related to the concept of numeric overflow, I initially had hopes that they chose to extend the HP-16C scheme instead. The sad truth is that we are faced with yet another stark incompatibility. This flag is for user programs to tell the calculator that it should stop on an overflow condition detected by the program. The corresponding system flag that a program might test to check whether the machine itself has encountered an overflow condition is flag 6 instead.

Now consider the HP-42S flag scheme, wholly different again:

Already we can see still another discrepancy: any “overflow” flag equivalent would have to be a double-digit value since the candidates above — 5, 6, and 9 — are all the single-digit values, whereas the HP-42S reserves those for user flags, off-limits for the calculator’s own uses.

And here’s the final trick: the HP-42S lacks a way to signal an overflow condition to user programs, period. It even lacks the 32S scheme for allowing a user program to tell the calculator to raise an overflow error to the user on its behalf. The closest equivalent I can see is flag 24, which allows a user program to tell the calculator to ignore range errors outright.

You might wonder why HP introduced two calculators in the same year (1988) with such different flag schemes.

I characterized the HP-32S as a logical successor to the 11C because it actually started a new evolutionary line. Its three successors — the HP-32SII, the HP 33s, and the HP 35s, spanning 1988 through 2007 — all shared a single flag scheme.

Contrast the HP-42S, which was not wholly new; it is a follow-on to the HP-41 line, introduced in 1979, meant to retain as much compatibility as possible given its very different hardware design. HP-41 series user flags overlap the first range on the 42S exactly. Control and system flags have different ranges — 11-29 and 30-55, respectively — but they actually overlap as well as one can expect.

A fan of that line might therefore wish that the R47 had continued this broad upwards compatibility. What its developers chose to do instead is a subject for later sections, but the important thing to realize at this point is that if you are translating old HP-41/42 programs, plan on manually mapping the historical flag numbers to the R47’s scheme.

System Flags

We can begin with the fact that the R47 does not make the same distinctions for calculator-defined flags as the HP-41/42S series, where all system flags were read-only by definition, and the user-changable ones were called the control flags. In the R47, the primary division is instead between user and system flags, where these last may further be marked as read-only.

More important is that R47 system flags are named. R47 programmers coming from this historical background no longer need to memorize system/control flag numbers or look them up in reference appendices.

While there is an underlying numbering scheme, it is primarily of interest to those spelunking the R47 code itself.2

Whereas the HP-42S made you say…

CF 30

…to temporarily clear the automatic stack lift flag from within a program, on the R47 you say instead…

CF ‘ASLIFT’

While you could type that argument out in alpha mode within program entry mode, the complete — yet shorter and therefore more likely — key sequence is:

🟧 FLAG CF
SYS.FL A ASLIFT

That is to say, you select the flag from a copy of the same menu you get via 🟧 PREF CFLG, which is the interactive path for examining system flag settings — especially read-only ones — and changing the read-write ones. The “A” keypress via the overloaded 𝑥² button is optional; it merely saves you some amount of arrowing through the scrolling flag menu. Since it is one of the last flags beginning with “A,” this single hint to the R47 causes it to end up on the bottom menu row, immediately above F3 in the current firmware.

Global User Flags

Given the above facts about the R47:

…it should not be surprising to learn that all 100 two-digit flags are available to the user on the R47, not just the 00-10 range from the HP-41 series plus the 80-99 range tacked on by the HP-42S. We are now free in our programs to say:

SF 47

(That particular flag had no predefined meaning on the 41 series, but because it became a read-only condition indicator on the HP-42S, that command produces a “Restricted Operation” error.)

You can see the current values of these user flags via 🟦 FLGS, where the first page shows a 10×10 grid of these user flags, all cleared by default and shown as black-on-light-gray text, but shown as inverse text — light gray on a black rectangle — when the flag is set.

These 100 flags are shared by all programs on a given R47, which brings us to…

Local User Flags

Any time you use the LocR feature in a program to allocate some number of local registers, it also automatically allocates 32 local flags. They are named using the same dot-prefixed scheme so that…

SF .31

…sets the last available “local” flag in the current subroutine scope.

Because the limit is currently 00-31,3 entering any digit 4-9 for a CF/SF call in a program immediately terminates the input. It interprets your single entered digit as 04 thru 09 because no legal two-digit value exists with that in the tens place. When you enter a 3 as the first digit, it refuses to accept anything but 0 or 1 for the second digit on the same grounds.

Named Global Flags

In addition to the 100 numbered global user flags, there are an additional 26 named global user flags defined in the R47 code, but only the first half are safe to use at the moment.

Try this:

🟧 PRGM
…navigate to a program space we can change…
🟧 FLAG SF A

That last is a press of the overloaded 𝑥² button to enter the A directly instead of picking it off the softmenu with the F3 key, because that does not work as of firmware 0.109.03.00a2. Nor does this:

🟧 FLAG SF F3(X)

It appears to be due to functionality defined but not completely coded. Until this is fixed, limit yourself to A-M for named global flags, and enter them via the keyboard overloads, not via the softmenus.

(You may now wish to return to my R47 article index.)

License

This work is © 2026 by Warren Young and is licensed under CC BY-NC-SA 4.0


  1. ^ $ grep -c 'fn.*FLAG_' ~/src/c47/master/src/c47/items.c
  2. ^ In the R47, flag values overlap its 16-bit item ID scheme because they are themselves “items” in this sense. System flags have the top bit set — 8000#h — but if it also has bit 14 set — C000#h — it is read-only. Thus, all the other “items” defined in the R47 can be treated as positive integers, limited to the lower 14 bits, giving them a range of 1-16383. Item 0 is a special “item to be coded” value, connoting both planned but yet-unimplemented functionality and also reserved ranges where there are no credible plans for their imminent use.
  3. ^ There was a time when the C47 allowed use of R.00 thru R.99 following a LocR call, but my brief attempt at code archaeology suggests they did not want to devote that big a chunk of the item ID space merely to accommodate a low-probability desire for more than 32 local flags.