Boolean and Bits logical operators

The complete source of operators_logic.ek9, compiled by the EK9 compiler. Shown on operators.html.

#!ek9
defines module site.operators.logic

  defines function

    booleanOperators()
      stdout <- Stdout()

      //Simple boolean values
      a <- true
      b <- true
      c <- false

      //Each of the operators
      //The and/not operator
      andAB <- a and b //result would be true
      andAC <- a and c //result would be false
      andNotC <- a and not c //result would be true
      andTildeC <- a and ~c //result would be true

      //The or/not operator
      orAB <- a or b //result would be true
      orAC <- a or c //result would be true
      notAOrC <- not a or c //result would be false
      tildeAOrC <- ~a or c //result would be false

      //The xor/not operator
      xorAB <- a xor b //result would be false
      xorANotB <- a xor not b //result would be true
      xorAC <- a xor c //result would be true
      notAXorC <- not a xor c //result would be false
      tildeAXorC <- ~a xor c //result would be false

      stdout.println(`${andAB} ${andAC} ${andNotC} ${andTildeC}`)
      stdout.println(`${orAB} ${orAC} ${notAOrC} ${tildeAOrC}`)
      stdout.println(`${xorAB} ${xorANotB} ${xorAC} ${notAXorC} ${tildeAXorC}`)

    bitsOperators()
      stdout <- Stdout()

      //Simple bits values
      a <- 0b010011
      b <- 0b101010
      c <- 0B01010011

      //Each of the operators
      //The not operator
      notA <- not a //result would be 0b101100

      //The and operator
      andAB <- a and b //result would be 0b000010

      //The or operator
      orAB <- a or b //result would be 0b111011

      //The xor operator
      xorAB <- a xor b //result would be 0b111001

      //The << operator
      shiftedOne <- c << 1 //result would be 0b010100110
      shiftedTwo <- c << 2 //result would be 0b0101001100

      //The >> operator
      shiftedRight <- c >> 2 //result would be 0b010100

      stdout.println(`${notA} ${andAB} ${orAB} ${xorAB}`)
      stdout.println(`${shiftedOne} ${shiftedTwo} ${shiftedRight}`)

  defines program

    Logic()
      booleanOperators()
      bitsOperators()

Download operators_logic.ek9

Output

true false true true
true true false false
false true true false false
101100 000010 111011 111001
010100110 0101001100 010100