lshift

lshift (value shiftCount -- shiftedValue)

Inputs

Outputs

lshift consumes two Whole values. value provides the bits to shift and the schema of the result. shiftCount provides the shift amount and may use a different Whole schema.

The bits of value move to the left. Zero bits are inserted at the low end and bits shifted past the high end are discarded.

The result always keeps the same schema as value.

Behavior

Example

{} () {} [
  "-- nat32 --" printCompilerMessage
  3n32 2 lshift printStack _:;
  3n32 1i8 lshift printStack _:;

  "-- nat8 dropped bits --" printCompilerMessage
  0x80n8 1 lshift printStack _:;

  "-- zero and unknown shift --" printCompilerMessage
  unknownShift: 0n32 dynamic;
  0n32 unknownShift lshift printStack _:;

  "-- unknown value and zero shiftCount --" printCompilerMessage
  unknownNat: 0n32 dynamic;
  unknownNat 0 lshift printStack _:;

  "-- int32 --" printCompilerMessage
  5 1 lshift printStack _:;
  1 31 lshift printStack _:;
] "main" exportFunction

Expected Output During Compilation

-- nat32 --
12n32
6n32
-- nat8 dropped bits --
0n8
-- zero and unknown shift --
0n32
-- unknown value and zero shiftCount --
Nat32
-- int32 --
10
-2147483648

See also