开发学院WEB开发ASP asp各种进制相互转换函数大全 阅读

asp各种进制相互转换函数大全

 2009-05-04 10:40:39 来源:WEB开发网   
核心提示:程序代码<%a=26b=11010c=26d=00100110e=26f=010110g=26h="1A"j=26k=32l=26m=46response.Write(cBit(a))response.Write("<br>")response.Write(cD

程序代码
<%
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
%>

Tags:asp 各种 进制

编辑录入:爽爽 [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接