Positron Compiler Documentation

Bitwise Shift Left '<<'

Positron8 · Revision 4.0.6.5 · PDF page 90

Assignment Variable = Variable << Shift_Amount

Shifts the bits of an integer value to the left a specified number of places. Bits shifted off the left end of a number are lost, and bits shifted into the right end of the number are 0s. Shifting the bits of a value left n number of times also has the effect of unsigned multiplying that number by two to the nth power.

For example 100 << 3 (shift the bits of the decimal number 100 left three places) is equivalent to 100 * 2 ^ 3.

Variable can be a constant, variable or expression that holds the value to shift. Shift_Amount can be a constant, variable or expression that holds the amount of shifts to perform. Assignment Variable can be any valid variable type.

Device = 18F26K40                  ' Select the device to compile for
Declare Xtal = 16  ' Tell the compiler the device will be operating at 16MHz
Declare Hserial_Baud = 9600        ' Set the Baud rate for HRsoutLn

Dim Wordin  as Word
Dim bMyLoop as Byte

Wordin = 0b1111111111111111
For bMyLoop = 1 To 16              ' Repeat with bMyLoop = 1 to 16.
  HRsoutLn Bin Wordin << bMyLoop   ' Shift variable Wordin left bMyLoop places.
Next

Bitwise operations are not permissible with floating point constants or variables.

Left shifts are unsigned, regardless of the variable type used.

View original PDF page 90Open page in PDFOriginal PDF page 90