; Shl Example ; ----------- ; Shl shifts a value's bits to the left: each shift doubles the value. ; (Shr shifts right to halve; Sar is a right shift that keeps the ; sign.) Bin$ shows the bits so you can watch them move. value=100 Print "value = "+Bin$(value)+" ("+value+")" Print "value Shl 1 = "+Bin$(value Shl 1)+" ("+(value Shl 1)+")" Print "value Shl 3 = "+Bin$(value Shl 3)+" ("+(value Shl 3)+")" Print "" Print "value Shr 1 = "+Bin$(value Shr 1)+" ("+(value Shr 1)+")" Print "value Shr 3 = "+Bin$(value Shr 3)+" ("+(value Shr 3)+")" Print "" ; On NEGATIVE numbers Shr and Sar differ: Shr shifts zeros in from ; the left (the sign is lost), Sar copies the sign bit (stays negative) neg=-100 Print "neg = "+Bin$(neg)+" ("+neg+")" Print "neg Shr 2 = "+Bin$(neg Shr 2)+" ("+(neg Shr 2)+")" Print "neg Sar 2 = "+Bin$(neg Sar 2)+" ("+(neg Sar 2)+")" Print "" Print "Press any key to close the example" WaitKey End