本帖最后由 3mile 于 2010-8-5 13:46 编辑
很久以前做的进制转换,不知道有用吗?$iNumber = InputBox("", "")
$time=TimerInit()
$hex=_DecToHex($iNumber)
MsgBox(0,"十进制转十六进制",$hex)
MsgBox(0,"十六进制转十进制",_hexToDec($hex))
$bin=_dectobin($iNumber)
MsgBox(0,"十进制转二进制",$bin)
MsgBox(0,"二进制转十进制",_BinToDec($bin))
Func _DecToBin($iNumber)
Local $sOut
For $i = 31 To 0 Step -1
$sOut &= BitAND(BitShift($iNumber, $i), 1)
Next
Return $sOut
EndFunc ;==>Ten2Bin
Func _DecToHex(ByRef $iNumber)
If NOT StringRegExp($iNumber, "^\d+$") Then Return SetError(1, 0, "")
If $iNumber > 2147483648 Then Return SetError(1, 0, "")
$iNumber=StringFormat('0x%08X',Binary(Execute($iNumber)))
Return $iNumber
EndFunc
Func _HexToDec(ByRef $iNumber)
If Not StringInStr($iNumber,"0x") Then
$iNumber=Execute("0x"&$iNumber)
Else
$iNumber=Execute($iNumber)
EndIf
Return $iNumber
EndFunc
Func _BinToDec(ByRef $iNumber)
Dim $number
If NOT StringRegExp($iNumber, "^[01]{1,}$") Then Return SetError(1, 0, "")
For $i=0 To StringLen($iNumber)-1
$number+=StringMid($iNumber,StringLen($iNumber)-$i,1)*(2^$i)
Next
$iNumber=$number
Return $iNumber
EndFunc
|