Click to See Complete Forum and Search --> : [RESOLVED] Don't understand


Marraco
January 16th, 2009, 12:06 PM
this help link (No works in Firefox, only in IE)
ms-help://MS.VSCC.v90/MS.msdnexpress.v90.en/dv_vbalr/html/fdb93d25-81ba-417f-b808-41207bfb8440.htm

says:"Arithmetic shifts are not circular, which means the bits shifted off one end of the result are not reintroduced at the other end. In an arithmetic left shift, the bits shifted beyond the range of the result data type are discarded, and the bit positions vacated on the right are set to zero."

But then gives an example:
Dim pattern As Short = 192
' The bit pattern is 0000 0000 1100 0000.
Dim result4 As Short
'...
result4 = pattern << 17

The results of the previous example are as follows:
...
result4 is 384 (0000 0001 1000 0000).
...

but that result is only possible if the Shift IS circular.

then it says:

The shift amount for result4 is calculated as 17 AND 15, which equals 1.

I don't get it.

TheCPUWizard
January 16th, 2009, 08:18 PM
WHY did you skip the important line on that page:


To prevent a shift by more bits than the result can hold, Visual Basic masks the value of amount with a size mask that corresponds to the data type of pattern. The binary AND of these values is used for the shift amount.

Therefore for a 16 bit wuantity, the maximum shift is 15, so

0001 0001 = 17
0000 1111 = 15
============
0000 0001 = 1

The Data is Shifted by 1 bit when you ask for 17....

Marraco
January 20th, 2009, 06:00 AM
WHY did you skip the important line on that page:
...That was!
(Answer: Because my English is poor...:blush:)

Thanks CPU. I gonna tell Gandalf of you.