不错的主要用于加密的vbs(asp)位移运算类
' aother: 奔腾的心
' qq: 7180001
' date: 2008-01-17
class mshift
private m_lpower2(31)
public function rshift(byval lthis, byval lbits)
on error resume next
init
if (lbits <= 0) then
rshift = lthis
elseif (lbits > 63) then
' .. error ...
elseif (lbits > 31) then
rshift = 0
else
if (lthis and m_lpower2(31 - lbits)) = m_lpower2(31 - lbits) then
rshift = (lthis and (m_lpower2(31 - lbits) - 1)) * m_lpower2(lbits) or
m_lpower2(31)
else
rshift = (lthis and (m_lpower2(31 - lbits) - 1)) * m_lpower2(lbits)
end if
end if
end function
public function lshift(byval lthis, byval lbits)
on error resume next
init
if (lbits <= 0) then
lshift = lthis
elseif (lbits > 63) then
' ... error ...
elseif (lbits > 31) then
lshift = 0
else
if (lthis and m_lpower2(31)) = m_lpower2(31) then
lshift = (lthis and &h7fffffff) \ m_lpower2(lbits) or m_lpower2(31 - lbits)
else
lshift = lthis \ m_lpower2(lbits)
end if
end if
end function
private sub init()
on error resume next
m_lpower2(0) = &h1&
m_lpower2(1) = &h2&
m_lpower2(2) = &h4&
m_lpower2(3) = &h8&
m_lpower2(4) = &h10&
m_lpower2(5) = &h20&
m_lpower2(6) = &h40&
m_lpower2(7) = &h80&
m_lpower2(8) = &h100&
m_lpower2(9) = &h200&
m_lpower2(10) = &h400&
m_lpower2(11) = &h800&
m_lpower2(12) = &h1000&
m_lpower2(13) = &h2000&
m_lpower2(14) = &h4000&
m_lpower2(15) = &h8000&
m_lpower2(16) = &h10000
m_lpower2(17) = &h20000
m_lpower2(18) = &h40000
m_lpower2(19) = &h80000
m_lpower2(20) = &h100000
m_lpower2(21) = &h200000
m_lpower2(22) = &h400000
m_lpower2(23) = &h800000
m_lpower2(24) = &h1000000
m_lpower2(25) = &h2000000
m_lpower2(26) = &h4000000
m_lpower2(27) = &h8000000
m_lpower2(28) = &h10000000
m_lpower2(29) = &h20000000
m_lpower2(30) = &h40000000
m_lpower2(31) = &h80000000
end sub
end class
dim sft
set sft = new mshift
msgbox sft.rshift(200, 4)
msgbox sft.lshift(200, 4)
set sft = nothing
alert(200<<4);
alert(200>>4);