[Oberon] Bit manipulation in Oberon-07

Tomas Kral thomas.kral at email.cz
Wed Oct 24 14:47:30 CEST 2018


On Tue, 23 Oct 2018 22:34:19 +0000
"Skulski, Wojciech" <skulski at pas.rochester.edu> wrote:

> to know how to manipulate bits in an integer variable.

Hi,

For byte access I would have coded this, but how to access the
individual bits?

MODULE Bits;
  IMPORT SYSTEM, O := Out;
VAR
  wd: INTEGER; (*word*)
  b0, b1, b2, b3: BYTE; (*bytes, b0:LSB, b3:MSB, or MSB/LSB I often
  confuse :-( *)
  bit0, bit1, bit2, bit3, bit7: BYTE; (*bits' values*)

  PROCEDURE Show*;
  BEGIN
    wd := 0F3F2F1F0H;
    b0 := wd MOD 100H; O.Hex(b0); O.Ln; (*one cycle or more?*)
    b1 := wd DIV 100H MOD 100H; O.Hex(b1); O.Ln;
    b2 := wd DIV 10000H MOD 100H; O.Hex(b2); O.Ln;
    b3 := wd DIV 1000000H MOD 100H; O.Hex(b3); O.Ln;
    bit0 := b0 MOD ??; O.Hex(bit0); O.Ln;
    bit1 := b1 MOD ??; O.Hex(bit1); O.Ln;
    bit2 := b2 MOD ??; O.Hex(bit2); O.Ln;
    bit3 := b3 MOD ??; O.Hex(bit3); O.Ln;
    bit7 := b0 MOD ??; O.Hex(bit7); O.Ln;
  END Show;

BEGIN
END Bits.Show


-- 
Tomas Kral <thomas.kral at email.cz>


More information about the Oberon mailing list