如何写一个函数让任何一个正数算术右移8位呢。。

解决方案 »

  1.   

    Dim lngTemp As Long 
    lngTemp =(lngTemp And &HFF) / &H100&
      

  2.   

    dim i as long i = i /2^8 '右移八位
    i = i * 2^8 '左移八位
      

  3.   

    二进制转十进制
    Public Function Dec(ByVal n As String) As Double
         Dim i As Long, j As Long, dot As Long, prefix As Long
         prefix = Sgn(n)
         If prefix = -1 Then n = Mid(n, 2)
         dot = InStr(n, ".")
         If dot = 0 Then
              dot = Len(n) - 1
         Else
              n = Left(n, dot - 1) & Mid(n, dot + 1)
              dot = dot - 2
         End If
         For i = dot To dot - Len(n) + 1 Step -1
              j = j + 1
              If Mid(n, j, 1) <> 0 Then Dec = Dec + 2 ^ i
         Next
         Dec = Dec * prefix
    End Function
      

  4.   

    Function bindec(x As String) As Double ' 2 TO 10
    Dim a
    a = Split(x, ".")
    y = 0
    For i = 1 To Len(a(0))
    y = y + Mid(a(0), i, 1) * 2 ^ (Len(a(0)) - i)
    Next
    For i = 1 To Len(a(1))
    y = y + Mid(a(1), i, 1) / 2 ^ i
    Next
    bindec = y
    End Function
      

  5.   

    正整数的右移8位:dim a as longa=fix(a/2^8)楼上 northwolves(野性的呼唤) 的二进制转成十进制应该成为楼主的首选,很好!
      

  6.   

    将dim a 改成 dim a() as string也 可以
      

  7.   

    http://expert.csdn.net/Expert/topic/2218/2218189.xml?temp=.2579615高分求解:如何把任意二制制数转成一个两位十六进制数