[Oberon] Negative integer literals in Oberon

Andreas Pirklbauer andreas_pirklbauer at yahoo.com
Tue Apr 28 02:17:15 CEST 2020


   > As said everything can be done in Oberon and I‘m fan of Oberon, but a really good
   > high level abstraction (=language construct) for bit programming is unfortunately missing.


One way this could be done is the way Swift has implemented "bitwise operators":

   http://docs.swift.org/swift-book/LanguageGuide/AdvancedOperators.html

In addition to Int and UInt, the Swift programming language provides signed and *unsigned*
integers in 8, 16, 32, and 64 bit forms, i.e. integers of a *specific size*.

Bitwise NOT:
    let initialBits: UInt8 = 0b00001111
    let invertedBits = ~initialBits  // equals 11110000

Bitwise AND
    let firstSixBits: UInt8 = 0b11111100
    let lastSixBits: UInt8  = 0b00111111
    let middleFourBits = firstSixBits & lastSixBits  // equals 00111100

PS: Although Swift doesn’t actually specify how a signed or unsigned integer is represented
internally, the bitwise operators actually (implicitly) do. So this is somewhat against the “very
idea of a high-level language which is that it must not be defined with reference to a computer
(or compiler), but be clearly defined as an abstract machine, the language report”.

Still, having such operators for *unsigned* integers of a *specific* size would be nice to have.


















More information about the Oberon mailing list