[Oberon] Bit manipulation in Oberon-07

Skulski, Wojciech skulski at pas.rochester.edu
Wed Oct 24 17:59:18 CEST 2018


>> Is there any BITS-equivalent in Oberon-07?
> No.

Why not? I am assuming that the language designer(s) were well aware of the need to manipulate bits. So why is ORD there, but the counterpart is not?

> SYSTEM.VAL is the only short (endianness-dependent) version.

The goal is to manipulate bits in hardware. So they do not want to "correct for endianness". They need to take the words "as is" and access bits according to their positions within the word.

> The long, portable, endianness independent version is:

(* convert INTEGER „i" to SET „s" *)
s := {}; FOR n := 0 TO 31 DO IF ODD(i) THEN INCL(s, n) END; i := i DIV 2 END;

Thank you! We can wrap this as a BITS function. On the other hand, the SYSTEM.VAL is probably better not because of efficiency, but because they are trying to deal with hardware, which is the domain of SYSTEM anyway.

Thank you,

More information about the Oberon mailing list