Bit TEST, SET, etc operators.

jpl jpl.algol68@gmail.com
Tue Feb 3 18:27:25 GMT 2026


Hello Jose,

It is indeed desirable to remain with 1-based index for unity of array
indices and iterations unless there is a compelling reason to switch
to 0-based for bit numbering.

I appreciate your question about "some particular practical problem"
that would benefit.  After reflection, I came up with this rather mild
list:

1) Some practical uses of setting, clearing and testing bits would be
for various interactions with HW (say for embedded systems).
Zero-based bit naming is the most prevalent in HW design
documentation.  See for example Intel x86-64, arm64, or even RISCV
documentations all use zero-based bit indexing.

2) A more software related usage might be the use of bit-masking for
circular buffers which allows a wraparound without a conditional
statement.  For example, set bit 10 of the mask for a 1024 length
queue.

3) The clarity that the "bit significance" of the i-th bit has a
weight of 2^i reduces mental loading by avoiding the (i+1), and (i-1)
somersaults.

None of the above demonstrate a hefty benefit of zero-based numbering.
More likely, they are my personal preferences.

If others having a view on this will share their thoughts, I will
happily sit back, listen and learn.

Thanks for your work on all of this.
James

On Mon, Feb 2, 2026 at 9:36 PM Jose E. Marchesi <jemarch@gnu.org> wrote:
>
>
> Hello James.
>
> > Greetings All,
> >
> > It is exciting to be able to use the new bit operators, am already
> > using them to implement a "bit reversed counter" to allow efficient
> > bit reversed addressing for various FFT implementations.
> >
> > Question:  is the decision to use "NUMBIT is ONE based" a firm decision?
> >
> > In doing so, we are loser the nice mathematical property wherein a
> > bit's position (NUMBIT) is associated with its power of 2.
> >
> > With one based we have:
> >   b_3*2^2   +   b_2*2^1 +   b_1*2^0    in general b_i*2^(i-1)
> > instead of:
> >   b_2*2^2   +   b_1*2^1 +   b_0*2^0     in general  b_i*2^i
> >
> > It's not the end of the world, but can be a bit awkward and might be
> > more error prone (for math-related).
>
> This is a very good question.
>
> The SET, CLEAR and TEST operators are oriented to the view of a `bits'
> as a packet set of bits, rather than as a multiple of booleans.  So I
> think it would be ok to use zero based indexes if we wanted to.
>
> That said, I think I still prefer the one based indexes, if only because
> it maches better with the indexing of multiples that is so very often
> used in iterations.
>
> Do you have some particular practical problem that would benefit from
> the zero based indexing?


More information about the Algol68 mailing list