Click to See Complete Forum and Search --> : How we can implement right shifting a word in VB ?... pl help


Abdul Kareem
October 12th, 1999, 11:57 PM
Dear All,
How we can implement a right shifting of a word in VB?/// please heplp me

Thanks in advance
Kareem.

deepak_warrier
October 13th, 1999, 01:22 AM
dim w as long
'Don't instanciate to "Integer" due to overflow problems

w=&h89ab
'This is now a word(2bytes long)

w=w/2
'Division by 2 is right shift by 1 bit
'Division by 2 raised to 8 is rightshift by 1 byte

'Multiplication by 2 is leftshift by 1 bit, and so on





OK now, I hope.

Deepak

Lothar Haensler
October 13th, 1999, 01:43 AM
this code was published a while ago by (if I remember correctly) "Crazy D @ work"


private Function RShiftWord(byval w as Integer, byval c as Integer) as Integer
Dim dw as Long
If c = 0 then
RShiftWord = w
else
dw = w And &HFFFF&
dw = dw \ (2 ^ c)
RShiftWord = dw And &HFFFF&
End If
End Function