vb如何计算一个字节有几个位为1?
2个回答
展开全部
用下这个吧!可以完成的你的要求
Function GetBY(k As Long) As Integer
Static BasicB(1 To 32) As Long, LoadOK As Boolean
Dim i As Integer, j As Integer
If LoadOK = False Then
For i = 1 To 31
BasicB(i) = 2 ^ (i - 1)
Next
BasicB(32) = &H80000000
End If
For i = 1 To 32
If k And BasicB(i) Then j = j + 1
Next
GetBY = j
End Function
Function GetBY(k As Long) As Integer
Static BasicB(1 To 32) As Long, LoadOK As Boolean
Dim i As Integer, j As Integer
If LoadOK = False Then
For i = 1 To 31
BasicB(i) = 2 ^ (i - 1)
Next
BasicB(32) = &H80000000
End If
For i = 1 To 32
If k And BasicB(i) Then j = j + 1
Next
GetBY = j
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询