28,408
社区成员
发帖
与我相关
我的任务
分享
a= BinToDec("001001")
b= BinToDec("111000")
c = a And b
d = a Or b
Response.Write DecToBin(c)
Response.Write DecToBin(d)
Function DecToBin(intDec)
dim strResult
dim intValue
dim intExp
strResult = ""
intValue = intDEC
intExp = 65536
while intExp >= 1
if intValue >= intExp then
intValue = intValue - intExp
strResult = strResult & "1"
else
strResult = strResult & "0"
end if
intExp = intExp / 2
wend
DecToBin = strResult
End Function
Function BinToDec(strBin)
dim lngResult
dim intIndex
lngResult = 0
for intIndex = len(strBin) to 1 step -1
strDigit = mid(strBin, intIndex, 1)
select case strDigit
case "0"
' do nothing
case "1"
lngResult = lngResult + (2 ^ (len(strBin)-intIndex))
case else
' invalid binary digit, so the whole thing is invalid
lngResult = 0
intIndex = 0 ' stop the loop
end select
next
BinToDec = lngResult
End Function