Positron Compiler Documentation

Bitwise Shift Left '<<'

Positron16 · Revision 1.1.3.5 · PDF page 86

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; 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 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 = 24FJ64GA002             ' Select the device to compile for
Declare Xtal = 16      ' Tell the compiler the device will be operating at 16MHz

Declare Hserial_Baud = 9600       ' USART1 Baud rate
Declare Hrsout1_Pin = PORTB.14    ' Select the pin for TX with USART1

Dim MyWord as Word
Dim bLoop as Byte

PPS_Output(cOut_Pin_RP14, cOut_Fn_U1TX)  ' Make Pin RB14 U1TX

MyWord = %1111111111111111
For bLoop = 1 to 16                ' Repeat with bLoop = 1 to 16.
  HrsoutLn Bin MyWord << bLoop    ' Shift MyWord left bLoop places.
Next

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

All left bit shifts are unsigned, regardless of the variable type used.

View original PDF page 86Open page in PDFOriginal PDF page 86