In ASP, Bit Operator Left shift and Right shift

假如想象 提交于 2020-05-15 09:44:08

问题


Does anyone know left shift and right shift operator sample's? I'm new in ASP. I found Bit operators such as AND,OR,NOT only..


回答1:


For vbscript, left shift is accomplished by multiplication (i.e., var * 2 left shifts one position, var * 4 lefts shifts two positions, etc.) and right shift is accomplished by division (i.e., var \ 16 right shifts four positions).




回答2:


There are no direct methods for left and right shift in vbscript, but as this is a simple move of each digit in a set of bits left or right, which can be done by dividing by binary 10 (integer 2), here are helper methods that do this

Function LeftShift(pValue, pShift)

Dim NewValue, PrevValue, i
PrevValue = pValue
For i = 1 to pShift
    Select Case VarType(pValue)
        Case vbLong
            NewValue = (PrevValue And "&H3FFFFFFF") * 2
            If PrevValue And "&H40000000" Then NewValue = NewValue Or "&H80000000"
            NewValue = CLng(NewValue)
        Case vbInteger
            NewValue = (PrevValue And "&H3FFF") * 2
            If PrevValue And "&H4000" Then NewValue = NewValue Or "&H8000"
            NewValue = CInt("&H"+ Hex(NewValue))
        Case vbByte
            NewValue = CByte((PrevValue And "&H7F") * 2)
        Case Else: Err.Raise 13 ' Not a supported type 
    End Select
    PrevValue = NewValue
Next
LeftShift = NewVAlue

End Function    

Function RightShift(pValue, pShift)

Dim NewValue, PrevValue, i
PrevValue = pValue
For i = 1 to pShift
    Select Case VarType(pValue)
        Case vbLong
            NewValue = Int((PrevValue And "&H7FFFFFFF") / 2)
            If PrevValue And "&H80000000" Then NewValue = NewValue Or "&H40000000"
            NewValue = CLng(NewValue)
        Case vbInteger
            NewValue = Int((PrevValue And "&H7FFF") / 2)
            If PrevValue And "&H8000" Then NewValue = NewValue Or "&H4000"
            NewValue = CInt(NewValue)
        Case vbByte
            NewValue = CByte(PrevValue / 2)
        Case Else: Err.Raise 13 ' Not a supported type
    End Select
    PrevValue = NewValue
Next
RightShift = PrevValue

End Function

For more, see http://chris.wastedhalo.com/2014/05/more-binarybitwise-functions-for-vbscript/




回答3:


http://www.blackwasp.co.uk/CSharpShiftOperators.aspx

That's C# but the same operators work in recent versions of VB.Net.



来源:https://stackoverflow.com/questions/3466413/in-asp-bit-operator-left-shift-and-right-shift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!