; Shr Example ; ----------- ; Shr shifts a value's bits to the right: each shift halves the value, ; with zeros arriving from the left. (Shl shifts left to double; Sar ; is the sign-keeping right shift.) Bin$ shows the bits moving. value=100 Print "value = "+Bin$(value)+" ("+value+")" Print "value Shr 1 = "+Bin$(value Shr 1)+" ("+(value Shr 1)+")" Print "value Shr 3 = "+Bin$(value Shr 3)+" ("+(value Shr 3)+")" Print "" Print "value Shl 1 = "+Bin$(value Shl 1)+" ("+(value Shl 1)+")" Print "value Shl 3 = "+Bin$(value Shl 3)+" ("+(value Shl 3)+")" Print "" ; On NEGATIVE numbers beware: Shr shifts zeros in from the left, so ; the sign bit is lost and the result is a huge positive number. ; Use Sar when you want a right shift that 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