当前位置:96看吧 > 技术文档 > ASP编程 > asp各进制转换函数

asp各进制转换函数

时间:2009/01/14
作者:诚心(MaWenDong)
来源:96看吧
查看:
标签:asp函数
<%
a = 26
b = 11010
c = 26
d = 00100110
e = 26
f = 010110
g = 26
h = "1A"
j = 26
k = 32
l = 26
m = 46
response.Write(cBit(a))
response.Write("<br>")
response.Write(cDec(b))
response.Write("<br>")
response.Write(HcB(c))
response.Write("<br>")
response.Write(BcH(d))
response.Write("<br>")
response.Write(OcB(e))
response.Write("<br>")
response.Write(BcO(f))
response.Write("<br>")
response.Write(Hex(g))
response.Write("<br>")
response.Write(HcD(h))
response.Write("<br>")
response.Write(Oct(j))
response.Write("<br>")
response.Write(OcD(k))
response.Write("<br>")
response.Write(HcO(l))
response.Write("<br>")
response.Write(OcH(m))

 

'///////////////////////////////////////

Function cBit(num)'十进制转二进制
    cBitstr = ""
    If Len(num)>0 And IsNumeric(num) Then
        Do While Not num \ 2 < 1
            cBitstr = (num Mod 2) &cBitstr
            num = num \ 2
        Loop
    End If
    cbit = num&cBitstr
End Function

'/////////////////////////////////////

Function cDec(num)'二进制转十进制
    cDecstr = 0
    If Len(num)>0 And IsNumeric(num) Then
        For inum = 0 To Len(num) -1
            cDecstr = cDecstr + 2^inum * CInt(Mid(num, Len(num) - inum, 1))
        Next
    End If
    cDec = cDecstr
End Function

'/////////////////////////////////

Function BcH(num)'二进制转十六进制
    BcH = Hex(cDec(num))
End Function

'//////////////////////////////////////

Function HcB(num)'十六进制转二进制
    If Len(num)>0 Then
        HcBstr = ""
        For i = 1 To Len(num)
            Select Case (Mid(num, i, 1))
                Case "0" HcBstr = HcBstr&"0000"
                Case "1" HcBstr = HcBstr&"0001"
                Case "2" HcBstr = HcBstr&"0010"
                Case "3" HcBstr = HcBstr&"0011"
                Case "4" HcBstr = HcBstr&"0100"
                Case "5" HcBstr = HcBstr&"0101"
                Case "6" HcBstr = HcBstr&"0110"
                Case "7" HcBstr = HcBstr&"0111"
                Case "8" HcBstr = HcBstr&"1000"
                Case "9" HcBstr = HcBstr&"1001"
                Case "A" HcBstr = HcBstr&"1010"
                Case "B" HcBstr = HcBstr&"1011"
                Case "C" HcBstr = HcBstr&"1100"
                Case "D" HcBstr = HcBstr&"1101"
                Case "E" HcBstr = HcBstr&"1110"
                Case "F" HcBstr = HcBstr&"1111"
            End Select
        Next
    End If
    HcB = HcBstr
End Function

'//////////////////////////

Function OcB(num)'八进制转二进制
    OcBstr = ""
    If Len(num)>0 And IsNumeric(num) Then
        For i = 1 To Len(num)
            Select Case (Mid(num, i, 1))
                Case "0" OcBstr = OcBstr&"000"
                Case "1" OcBstr = OcBstr&"001"
                Case "2" OcBstr = OcBstr&"010"
                Case "3" OcBstr = OcBstr&"011"
                Case "4" OcBstr = OcBstr&"100"
                Case "5" OcBstr = OcBstr&"101"
                Case "6" OcBstr = OcBstr&"110"
                Case "7" OcBstr = OcBstr&"111"
            End Select
        Next
    End If
    OcB = OcBstr
End Function

'////////////////////////////

Function BcO(num)'二进制转八进制
    BcO = Oct(cDec(num))
End Function

'///////////////////////////

Function OcD(num)'八进制转十进制
    OcD = cDec(OcB(num))
End Function

'十进制转八进制 Oct(num)
'///////////////////

Function HcD(num)'十六进制转十进制
    HcD = cDec(HcB(num))
End Function

'十进制转十六进制 Hex(num)
'////////////////////

Function HcO(num)'十六进制转八进制
    HcO = Oct(HcD(num))
End Function

'///////////////////

Function OcH(num)'八进制转十六进制
    OcH = Hex(OcD(num))
End Function
%>
 

上一篇:asp函数全角半角字符相互转换
下一篇:ASP不需要数据库生成中奖码
页面举报
Report
关闭页面
Close
收藏页面
Favorites
分享页面
Share
版权信息:栏目内,站内会员所分享的全部“资源/素材/文章”,仅供学习与参考,版权为原作者所有。
下载提示:非注册用户每天可下载一个文件,已注册会员不受限制。
网友评论
数据载入中
验证码
  • 请您注意:
  • ·请不要在评论中含与内容无关的广告链接。
  • ·不良评论请用报告管理员,以利管理员及时删除。
  • ·遵守中华人民共和国的各项有关法律法规
  • ·承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • ·本站管理人员有权保留或删除评论中的任意内容
  • ·您在本站发表的作品,本站有权在网站内转载或引用
  • ·参与本评论即表明您已经阅读并接受上述条款
相关最新
相关热门