我在vc++中看到这样语句
  x=x shr 1
这条句在VB中怎么表达呀

解决方案 »

  1.   

    右移一位:x=x\2
    左移一位:x=x*2
      

  2.   

    参考:
    http://www.cx66.com/cxgzs/program/vb/487.htm
      

  3.   

    刚才我发了一个不知道是不是你问的,在发一遍(参考)
    Private OnBits(0 To 31) As Long
    Public Function LShiftLong(ByVal Value As Long, _
        ByVal Shift As Integer) As Long
      
        MakeOnBits
      
        If (Value And (2 ^ (31 - Shift))) Then GoTo OverFlow
      
        LShiftLong = ((Value And OnBits(31 - Shift)) * (2 ^ Shift))
      
        Exit FunctionOverFlow:
      
        LShiftLong = ((Value And OnBits(31 - (Shift + 1))) * _
           (2 ^ (Shift))) Or &H80000000
      
    End FunctionPublic Function RShiftLong(ByVal Value As Long, _
       ByVal Shift As Integer) As Long
        Dim hi As Long
        MakeOnBits
        If (Value And &H80000000) Then hi = &H40000000
      
        RShiftLong = (Value And &H7FFFFFFE) \ (2 ^ Shift)
        RShiftLong = (RShiftLong Or (hi \ (2 ^ (Shift - 1))))
    End Function
     
    Public Enum dcShiftDirection
        Left = -1
        Right = 0
    End EnumPublic Function Shift(ByVal lValue As Long, ByVal lNumberOfBitsToShift As Long, ByVal lDirectionToShift As dcShiftDirection) As Long
        Const ksCallname As String = "Shift"
        On Error GoTo Procedure_Error
        Dim LShift As Long
        If lDirectionToShift Then 'shift left
            LShift = lValue * (2 ^ lNumberOfBitsToShift)
        Else 'shift right
            LShift = lValue \ (2 ^ lNumberOfBitsToShift)
        End If
        
    Procedure_Exit:
        Shift = LShift
        Exit Function
        
    Procedure_Error:
        Err.Raise Err.Number, ksCallname, Err.Description, Err.HelpFile, Err.HelpContext
        Resume Procedure_Exit
    End FunctionPublic Function LShift(ByVal lValue As Long, ByVal lNumberOfBitsToShift As Long) As Long
        Const ksCallname As String = "LShift"
        On Error GoTo Procedure_Error
        LShift = Shift(lValue, lNumberOfBitsToShift, Left)
        
    Procedure_Exit:
        Exit Function
        
    Procedure_Error:
        Err.Raise Err.Number, ksCallname, Err.Description, Err.HelpFile, Err.HelpContext
        Resume Procedure_Exit
    End Function
    Public Function RShift(ByVal lValue As Long, ByVal lNumberOfBitsToShift As Long) As Long
        Const ksCallname As String = "RShift"
        On Error GoTo Procedure_Error
        RShift = Shift(lValue, lNumberOfBitsToShift, Right)
        
    Procedure_Exit:
        Exit Function
        
    Procedure_Error:
        Err.Raise Err.Number, ksCallname, Err.Description, Err.HelpFile, Err.HelpContext
        Resume Procedure_Exit
    End Function
    Private Sub MakeOnBits()
        Dim j As Integer, _
            v As Long
      
        For j = 0 To 30
      
            v = v + (2 ^ j)
            OnBits(j) = v
      
        Next j
      
        OnBits(j) = v + &H80000000End Sub
      

  4.   

    右移一位:x=x\2
    左移一位:x=x*2
    应该是这样的.