窗外请进

victorycyz 2004-06-11 01:45:53

给你一个2进制字串转十进制的VB算法,仅供参考。如有兴趣,请自行转化为SQL函数。

每次处理的字串最大长度为31位。


Function Bin2Dec(value As String) As Long

Dim Result As Long, i As Integer, Exponent As Integer
For i = Len(value) To 1 Step -1
Select Case Asc(Mid$(value, i, 1))
Case 48
Case 49
Result = Result + Power2(Exponent)
Case Else
Err.Raise 5 'invalid procedure call or argument
End Select
Exponent = Exponent + 1
Next
Bin2Dec = Result

End Function

Function Power2(ByVal Exponent As Long) As Long

Static Result(0 To 31) As Long, i As Integer
If Result(0) = 0 Then
Result(0) = 1
For i = 1 To 30
Result(i) = Result(i - 1) * 2
Next
Result(31) = &H80000000
End If
Power2 = Result(Exponent)

End Function
...全文
117 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
victorycyz 2004-06-14
  • 打赏
  • 举报
回复

WhbtomT(半路出家) 谢谢。不着急。



位运算之后,从10进制再转回2进制:

Function Bin(byval value as long) as string
dim result as string, exponent as integer
result=string$(32,"0")
do
if value as power2(exponent) then
mid$(result,32-exponent,1)="1"
value=value xor power2(exponent)
end if
exponent=exponent+1
loop while value
bin=mid$(result,33-exponent)
end function
WhbtomT 2004-06-11
  • 打赏
  • 举报
回复
To Victorycyz:

我得找一找, 机子的系统坏过.
outwindows 2004-06-11
  • 打赏
  • 举报
回复
?
angeltears 2004-06-11
  • 打赏
  • 举报
回复
跳窗逃跑???
internetcsdn 2004-06-11
  • 打赏
  • 举报
回复
哈哈,


可用分多了三百.

现在论坛有点混来的了....
internetcsdn 2004-06-11
  • 打赏
  • 举报
回复
找回来了?
outwindows 2004-06-11
  • 打赏
  • 举报
回复
谢谢...
victorycyz 2004-06-11
  • 打赏
  • 举报
回复

当然可以。

每日英语还有第31、32天的没有找回来,能重贴一下吗?谢谢。
WhbtomT 2004-06-11
  • 打赏
  • 举报
回复
出家人可以进来么?

分又回来了。

11,849

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 非技术版
社区管理员
  • 非技术版社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧