从官网找来的转成二进制
; ==============================================================================================; Func _NumberToBinary($iNumber)
;
; Converts a 32-bit signed or unsigned # to a binary bit string. (32-bit is AutoIT limit)
; NOTE: range for 32-bit values is -2147483648 to 4294967295
; Anything outside the range will return an empty string!
;
; $iNumber = # to convert, obviously
;
; Returns:
; Success: Binary bit string
; Failure: "" and @error set
;
; Author: Ascend4nt, with help from picaxe (Changing 'If BitAND/Else' to just one line)
; See it @ http://www.autoitscript.com/forum/index.php?showtopic=90056
; ==============================================================================================
MsgBox(0,'',_NumberToBinary(13))
Func _NumberToBinary($iNumber)
Local $iTopBit,$sBinString = ""
; Maximum 32-bit # range is -2147483648 to 4294967295
If $iNumber<-2147483648 Or $iNumber>4294967295 Then Return SetError(1,0,"")
; Any number <0 or >2147483647 will have the 32nd (top) bit set
If $iNumber>2147483647 Or $iNumber<0 Then
$iTopBit=1
Else
$iTopBit=0
EndIf
; Remove topbit, otherwise the function will enter an endless loop
Local $iUnsignedNumber=BitAND($iNumber,0x7FFFFFFF)
; Cycle through each bit, shifting to the right until 0
Do
$sBinString = BitAND($iUnsignedNumber, 1) & $sBinString
$iUnsignedNumber = BitShift($iUnsignedNumber, 1)
Until Not $iUnsignedNumber
; PAD to 32-bits (or alternatively see below for #'s that don't need it)
Return $iTopBit & StringRight("000000000000000000000000000000" &$sBinString,31)
; If you prefer not to pad numbers that don't need it (anything >0 and <2147483647):
#cs
If $iTopBit Then Return $iTopBit & StringRight("000000000000000000000000000000" & $sBinString,31)
Return $sBinString
#ce
EndFunc ;==>_NumberToBinary 刚好用到~再找一个2进制转10进制的吧:face (29): 原帖由 298311657 于 2009-3-15 21:47 发表 http://www.autoitx.com/images/common/back.gif
刚好用到~再找一个2进制转10进制的吧:face (29):
建议你自己写个! 用是能用,不过用过后会卡一下下。还不是很完美。 自己写个也不难,懂得进制转换算法就好办。以下是10<->2,16<->2,16<->10的UDF。
问题是AU3超大数的限制,还有32位数字限制。上次要写个REG_QWORD类型注册表值读写,最后还是没做好,有谁写过的能指点一下吗?
;===============================================================================
; 说明: 十进制转换为二进制
; 语法: _DecToBinary($sDecStr[, $iLength = 0])
; 参数: $sDecStr - 需要转换的十进制字符
; $iLength - [可选] 返回长度
; 需要: 无
; 返回: 成功 - 二进制字符
; 失败 - 空字符 "", 并设置 @error 到 1
; 备注: 限制: 1125899906842622d / 3fffffffffffeh
;===============================================================================
Func _DecToBinary($sDecStr, $iLength = 0)
Local $sBinStr = ""
If NOT StringRegExp($sDecStr, "^\d+$") Then Return SetError(1, 0, "")
If $sDecStr > 1125899906842622 Then Return SetError(1, 0, "")
While $sDecStr > 0
$sBinStr = Mod($sDecStr, 2) & $sBinStr
$sDecStr = Int($sDecStr / 2)
WEnd
While StringLen($sBinStr) < $iLength
$sBinStr = "0" & $sBinStr
WEnd
Return $sBinStr
EndFunc ;==>_DecToBinary
;===============================================================================
; 说明: 二进制转换为十进制
; 语法: _BinaryToDec($sBinStr)
; 参数: $sBinStr - 需要转换的二进制字符
; 需要: 无
; 返回: 成功 - 十进制整数
; 失败 - 空字符 "", 并设置 @error 到 1
; 备注: 限制: 9223372036854775807d / 7fffffffffffffffh / {1,63}b
; 注意: 输入超过 999999999999999d / 38d7ea4c67fffh 将输出指数形式
;===============================================================================
Func _BinaryToDec($sBinStr)
Local $sDecStr = 0
If NOT StringRegExp($sBinStr, "^{1,63}$") Then Return SetError(1, 0, "")
For $i = 1 To StringLen($sBinStr)
$sDecStr = $sDecStr * 2 + StringMid($sBinStr, $i, 1)
Next
Return $sDecStr
EndFunc ;==>_BinaryToDec
;===============================================================================
; 说明: 十六进制转换为二进制
; 语法: _HexToBinary($sHexStr[, $iLength = 0])
; 参数: $sHexStr - 需要转换的十六进制字符
; $iLength - [可选] 返回长度
; 需要: 无
; 返回: 成功 - 二进制字符
; 失败 - 空字符 "", 并设置 @error 到 1
; 备注: 限制: 输出最大 2147483647 个字符
;===============================================================================
Func _HexToBinary($sHexStr, $iLength = 0)
Local $sBinStr = ""
If NOT StringRegExp($sHexStr, "^+$") Then Return SetError(1, 0, "")
$sHexStr = StringUpper($sHexStr)
For $i = 1 To StringLen($sHexStr)
Switch StringMid($sHexStr, $i, 1)
Case "0"
$sBinStr &= "0000"
Case "1"
$sBinStr &= "0001"
Case "2"
$sBinStr &= "0010"
Case "3"
$sBinStr &= "0011"
Case "4"
$sBinStr &= "0100"
Case "5"
$sBinStr &= "0101"
Case "6"
$sBinStr &= "0110"
Case "7"
$sBinStr &= "0111"
Case "8"
$sBinStr &= "1000"
Case "9"
$sBinStr &= "1001"
Case "A"
$sBinStr &= "1010"
Case "B"
$sBinStr &= "1011"
Case "C"
$sBinStr &= "1100"
Case "D"
$sBinStr &= "1101"
Case "E"
$sBinStr &= "1110"
Case "F"
$sBinStr &= "1111"
EndSwitch
Next
If $iLength = 0 Then
While StringLeft($sBinStr, 1) = "0"
$sBinStr = StringTrimLeft($sBinStr, 1)
WEnd
Else
For $i = 1 To $iLength - StringLen($sBinStr)
$sBinStr = "0" & $sBinStr
Next
EndIf
Return $sBinStr
EndFunc ;==>_HexToBinary
;===============================================================================
; 说明: 二进制转换为十六进制
; 语法: _BinaryToHex($sBinStr[, $iLength = 0])
; 参数: $sBinStr - 需要转换的二进制字符
; $iLength - [可选] 返回长度
; 需要: 无
; 返回: 成功 - 十六进制字符
; 失败 - 空字符 "", 并设置 @error 到 1
; 备注: 限制: 输入最大 2147483647 个字符
;===============================================================================
Func _BinaryToHex($sBinStr, $iLength = 0)
Local $sHexStr = ""
If NOT StringRegExp($sBinStr, "^+$") Then Return SetError(1, 0, "")
While Mod(StringLen($sBinStr), 4)
$sBinStr = "0" & $sBinStr
WEnd
For $i = 1 To StringLen($sBinStr) Step 4
Switch StringMid($sBinStr, $i, 4)
Case "0000"
$sHexStr &= "0"
Case "0001"
$sHexStr &= "1"
Case "0010"
$sHexStr &= "2"
Case "0011"
$sHexStr &= "3"
Case "0100"
$sHexStr &= "4"
Case "0101"
$sHexStr &= "5"
Case "0110"
$sHexStr &= "6"
Case "0111"
$sHexStr &= "7"
Case "1000"
$sHexStr &= "8"
Case "1001"
$sHexStr &= "9"
Case "1010"
$sHexStr &= "A"
Case "1011"
$sHexStr &= "B"
Case "1100"
$sHexStr &= "C"
Case "1101"
$sHexStr &= "D"
Case "1110"
$sHexStr &= "E"
Case "1111"
$sHexStr &= "F"
EndSwitch
Next
If $iLength = 0 Then
While StringLeft($sHexStr, 1) = "0"
$sHexStr = StringTrimLeft($sHexStr, 1)
WEnd
Else
For $i = 1 To $iLength - StringLen($sHexStr)
$sHexStr = "0" & $sHexStr
Next
EndIf
Return $sHexStr
EndFunc ;==>_BinaryToHex
;===============================================================================
; 说明: 十六进制转换为十进制
; 语法: _HexToDec($sHexStr)
; 参数: $sHexStr - 需要转换的十六进制字符
; 需要: 无
; 返回: 成功 - 十进制整数
; 失败 - 空字符 "", 并设置 @error 到 1
; 备注: 注意: 输入超过 999999999999999d / 38d7ea4c67fffh 将输出指数形式
;===============================================================================
Func _HexToDec($sHexStr)
Local $sDecStr = 0
If NOT StringRegExp($sHexStr, "^+$") Then Return SetError(1, 0, "")
$sHexStr = StringUpper($sHexStr)
For $i = 1 To StringLen($sHexStr)
Switch StringMid($sHexStr, StringLen($sHexStr) - $i + 1, 1)
Case "0"
$sDecStr = $sDecStr + 16 ^ ($i - 1) * 0
Case "1"
$sDecStr = $sDecStr + 16 ^ ($i - 1) * 1
Case "2"
$sDecStr = $sDecStr + 16 ^ ($i - 1) * 2
Case "3"
$sDecStr = $sDecStr + 16 ^ ($i - 1) * 3
Case "4"
$sDecStr = $sDecStr + 16 ^ ($i - 1) * 4
Case "5"
$sDecStr = $sDecStr + 16 ^ ($i - 1) * 5
Case "6"
$sDecStr = $sDecStr + 16 ^ ($i - 1) * 6
Case "7"
$sDecStr = $sDecStr + 16 ^ ($i - 1) * 7
Case "8"
$sDecStr = $sDecStr + 16 ^ ($i - 1) * 8
Case "9"
$sDecStr = $sDecStr + 16 ^ ($i - 1) * 9
Case "A"
$sDecStr = $sDecStr + 16 ^ ($i - 1) * 10
Case "B"
$sDecStr = $sDecStr + 16 ^ ($i - 1) * 11
Case "C"
$sDecStr = $sDecStr + 16 ^ ($i - 1) * 12
Case "D"
$sDecStr = $sDecStr + 16 ^ ($i - 1) * 13
Case "E"
$sDecStr = $sDecStr + 16 ^ ($i - 1) * 14
Case "F"
$sDecStr = $sDecStr + 16 ^ ($i - 1) * 15
EndSwitch
Next
Return $sDecStr
EndFunc ;==>_HexToDec
;===============================================================================
; 说明: 十进制转换为十六进制
; 语法: _DecToHex($sDecStr[, $iLength = 0])
; 参数: $sDecStr - 需要转换的十进制字符
; $iLength - [可选] 返回长度
; 需要: 无
; 返回: 成功 - 十六进制字符
; 失败 - 空字符 "", 并设置 @error 到 1
; 备注: 限制: 1125899906842622d / 3fffffffffffeh
;===============================================================================
Func _DecToHex($sDecStr, $iLength = 0)
Local $sHexStr = "", $sResult
If NOT StringRegExp($sDecStr, "^\d+$") Then Return SetError(1, 0, "")
If $sDecStr > 1125899906842622 Then Return SetError(1, 0, "")
While $sDecStr > 0
$sResult = Mod($sDecStr, 16)
Switch $sResult
Case "10"
$sResult = "A"
Case "11"
$sResult = "B"
Case "12"
$sResult = "C"
Case "13"
$sResult = "D"
Case "14"
$sResult = "E"
Case "15"
$sResult = "F"
EndSwitch
$sHexStr = $sResult & $sHexStr
$sDecStr = Int($sDecStr / 16)
WEnd
While StringLen($sHexStr) < $iLength
$sHexStr = "0" & $sHexStr
WEnd
Return $sHexStr
EndFunc ;==>_DecToHex
受教了,我需要的…… :face (30): 看一下,谢谢 新手学习下 认真学习一下! 不错不错 ,感谢分享, 呵呵 已经下载,感谢分享, 呵呵 缺钱啊 能不能不要钱啊 没办法啊,唉要下载资源不容易啊 谢谢分享东西,取消收费就好了
页:
[1]
2