vb 下进制转换(2-36)

Public Function cTon(ByVal sInNum As String, ByVal n As Double) As String
'转换至n进制(n<=36)
  Dim dx As Double, iX As Long
  Const sNum As String = "0123456789ABCDEFGHIJKLMNoPQRSTUVWXYZ"
  ''Const sNum As String = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ"
  If Not (Len(sInNum) > 0 And Len(sInNum) <= 15 And n > 0 And n <= 36) Then
   cTon = -1
  Exit Function
 
  dx = CDbl(sInNum)
  Do While dx > 0
    iX = dx - Int(dx / n) * n + 1           'iX = dX Mod n +1 用Mod会溢出
    cTon = Mid$(sNum, iX, 1) & cTon
    dx = Int(dx / n)
  Loop
End Function

Public Function nToc(ByVal sInNum As String, ByVal n As Double) As Double
  Dim iX As Long, iY As Long, i As Integer
  Const sNum As String = "123456789ABCDEFGHIJKLMNoPQRSTUVWXYZ"
  ''Const sNum As String = "123456789ABCDEFGHJKLMNPQRSTUVWXYZ"
  If (n >= 2 And n <= 36) Then
    iY = Len(sInNum)
    For iX = 0 To iY - 1
      i = InStr(1, sNum, Mid$(sInNum, iY - iX, 1), vbTextCompare)
      If i >= n Then
        nToc = -1
        Exit Function
      End If
      nToc = nToc + i * (n ^ iX)
    Next iX
  Else
    nToc = -1
    Exit Function
  End If
End Function

转载于:https://www.cnblogs.com/whfabc/archive/2009/06/22/1508264.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值