[解决]AU3有没有8/64/128/256进制的转换函数???
本帖最后由 邪恶海盗 于 2012-10-11 20:07 编辑如题,2/10/16貌似有,其它的暂时没找到,不知道有没有,大家帮忙瞧瞧吧... 本帖最后由 zch11230 于 2012-10-11 00:44 编辑
最笨的办法,按照我笔算的方法,一位一位算出来的,测试了几个数都还准确,不知道还有什么问题没有。。。。然后字母26个 所以最多也只能表示到36进制(听起好别扭。。。。)不知道楼主所需要的64,128,256怎么表示。。。。
刚才搜索论坛发现P版早就写好了。。。。
http://www.autoitx.com/forum.php?mod=viewthread&tid=32999
MsgBox(0, "", _10toN(65972, 16))
Func _10toN($num, $radix)
Local $convert, $result, $temp, $str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
If IsInt($num) And IsInt($radix) And $num >= 0 And $radix >= 2 And $radix<=36 Then
Do
$temp = Mod($num, $radix)
If $temp < 10 Then
$convert &= $temp
Else
$convert &= StringMid($str, $temp - 9, 1)
EndIf
$num = Int($num / $radix)
Until $num = 0
For $i = StringLen($convert) To 1 Step -1
$result &= StringMid($convert, $i, 1)
Next
Return ($result)
Else
Return ("error")
EndIf
EndFunc ;==>_10toN
本帖最后由 netegg 于 2012-10-11 11:09 编辑
exe帮助里带的math.au3里好像有_inttoany函数,十进制转任意进制
不过有个疑问,有64/128/256进制的数吗,怎么表示的?base64倒是听说过,不过是不是64进制的数不清楚了 Func _10ToN($iValue, $iHex)
If $iHex < 2 Or $iHex > 65 Then
Return SetError(1, 0, "")
EndIf
Local Const $KEY = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-+@"
Local $iMod, $sResult
While $iValue
$iMod = Mod($iValue, $iHex)
$sResult = StringMid($KEY, $iMod + 1, 1) & $sResult
$iValue = Int($iValue / $iHex)
WEnd
;Return StringFormat("(%d)%s", $iHex, $sResult)
Return $sResult
EndFunc
Func _NTo10($iValue, $iHex)
Local Const $KEY = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-+@"
Local $iValueLen = StringLen($iValue), $sResult
If $iHex < 2 Or $iHex > StringLen($KEY) Then
Return SetError(1, 0, "")
EndIf
For $i = 1 To $iValueLen
$sResult+=(StringInStr($KEY, StringMid($iValue, $i, 1),1)-1)* ($iHex^($iValueLen-$i))
Next
Return $sResult
EndFunc
试了一下,发现下面一个貌似直接可以NToN啊,10ToN那个是否多余了???
话说64/128/256我也不知道,昨天放狗的时候看有人提到的{:face (411):}
_inttoany在官方帮助里搜不到....
蛋哥,我那个拆字符串的问题咋解决呢??? _10ToN(55,36)
_NTo10(55,36)
又测试了一下,发现两个返回的结果不一样...
不知道_NTo10这个是将字符串认定为多少进制的,36么??? 摸索出来了:
_10ToN($iValue, $iHex);将10进制数$iValue转换为$iHex(<=36)数
_NTo10($iValue, $iHex);将$iHex(<=36)进制数$iValue转换为10进制数 回复 4# 邪恶海盗
exe里的math.au3里面有 回复 7# netegg
#include-once
; #INDEX# =======================================================================================================================
; Title .........: Mathematical calculations
; AutoIt Version : 3.0
; Language ......: English
; Description ...: Functions that assist with mathematical calculations.
; Author(s) .....: Valik, Gary Frost, ...
; ===============================================================================================================================
; #FUNCTION# ====================================================================================================================
; Name...........: _ATan2()
; Description ...: Returns the standard position angle (in radians) to the point ($nX, $nY).
; Syntax.........: _ATan2(Const $nY, Const $nX )
; Parameters ....: $nY = y co-ordinate of the point to check.
; $nX = x co-ordinate of the point to check.
; Return values .: On Success: = Returns the angle, between 0 and 2 pi.
; On Failure: = Sets @Error and returns 0, which can be a valid responce, so check @Error first.
; @ERROR: = 0 = No error.
; 1 = $nY or $nX is not a number.
; 2 = Point is at the origin.Can not determine direction.
; Author ........: "Nutster" David Nuttall <danuttall at rocketmail dot com>
; Remarks .......: Angles start from right being 0, and increasing upward from there.All angles are in radians.
; Example .......: MsgBox(4096, "ATan2() Test", "_ATan2( 3, 4 ) = " & _ATan2( 3, 4 ))
; ===============================================================================================================================
Func _ATan2(Const $nY, Const $nX)
Const $nPi = 3.14159265358979323846264338328
Local $nResult
; Check if given numeric arguments
If IsNumber($nY) = 0 Then
SetError(1)
Return 0
ElseIf IsNumber($nX) = 0 Then
SetError(1)
Return 0
EndIf
If $nX = 0 Then
If $nY > 0 Then
$nResult = $nPi / 2.0
ElseIf $nY < 0 Then
$nResult = 3.0 * $nPi / 2.0
Else
SetError(2) ; no direction can be determined.
Return 0
EndIf
ElseIf $nX < 0 Then
$nResult = ATan($nY / $nX) + $nPi
Else
$nResult = ATan($nY / $nX)
EndIf
While $nResult < 0
$nResult += 2.0 * $nPi
WEnd
Return $nResult
EndFunc ;==>_ATan2
; #FUNCTION# ====================================================================================================================
; Name...........: _Degree()
; Description ...: Converts radians to degrees.
; Syntax.........: _Degree( $nRadians )
; Parameters ....: $nRadians = Radians to be converted into degrees.
; Return values .: On Success: = Returns the degrees converted from radians.
; On Failure: = Returns a blank string.
; @ERROR: = 0 = No error.
; 1 = $nRadians is not a number.
; Author ........: Erifash <erifash at gmail dot com>
; Remarks .......: Multiplies instead of dividing.
; Example .......: MsgBox(4096, "_Degree() Test", "_Degree( 3.1415 ) = " & _Degree( 3.1415 ))
; ===============================================================================================================================
Func _Degree($nRadians)
If IsNumber($nRadians) Then Return $nRadians * 57.2957795130823
Return SetError(1, 0, "")
EndFunc ;==>_Degree
; #FUNCTION# ====================================================================================================================
; Name...........:_MathCheckDiv()
; Description ...:Checks to see if numberA is divisable by numberB
; Parameters ....:$i_NumA - Dividend
; $i_NumB - Divisor
; Return values .:On Success - 1 if not evenly divisable
; - 2 if evenly divisable
; On Failure - -1 and @error = 1
; Author ........:Wes Wolfe-Wolvereness <Weswolf at aol dot com>
; ===============================================================================================================================
Func _MathCheckDiv($i_NumA, $i_NumB = 2)
If Number($i_NumA) = 0 Or Number($i_NumB) = 0 Or Int($i_NumA) <> $i_NumA Or Int($i_NumB) <> $i_NumB Then
Return SetError(1, 0, -1)
ElseIf Int($i_NumA / $i_NumB) <> $i_NumA / $i_NumB Then
Return 1
Else
Return 2
EndIf
EndFunc ;==>_MathCheckDiv
; #FUNCTION# ====================================================================================================================
; Name...........: _Max()
; Description ...: Evaluates which of the two numbers is higher.
; Syntax.........: _Max( $nNum1, $nNum2 )
; Parameters ....: $nNum1 = First number
; $nNum2 = Second number
; Return values .: On Success: = Returns the higher of the two numbers
; On Failure: = Returns 0.
; @ERROR: = 0 = No error.
; 1 = $nNum1 isn't a number.
; 2 = $nNum2 isn't a number.
; Author ........: Jeremy Landes <jlandes at landeserve dot com>
; Remarks .......: Works with floats as well as integers
;
; Example .......: MsgBox( 4096, "_Max() - Test", "_Max( 3.5, 10 ) = " & _Max( 3.5, 10 ) )
; ===============================================================================================================================
Func _Max($nNum1, $nNum2)
; Check to see if the parameters are indeed numbers of some sort.
If Not IsNumber($nNum1) Then Return SetError(1, 0, 0)
If Not IsNumber($nNum2) Then Return SetError(2, 0, 0)
If $nNum1 > $nNum2 Then
Return $nNum1
Else
Return $nNum2
EndIf
EndFunc ;==>_Max
; #FUNCTION# ====================================================================================================================
; Name...........: _Min()
; Description ...: Evaluates which of the two numbers is lower.
; Syntax.........: _Min( $nNum1, $nNum2 )
; Parameters ....: $nNum1 = First number
; $nNum2 = Second number
; Return values .: On Success: = Returns the higher of the two numbers
; On Failure: = Returns 0.
; @ERROR: = 0 = No error.
; 1 = $nNum1 isn't a number.
; 2 = $nNum2 isn't a number.
; Author ........: Jeremy Landes <jlandes at landeserve dot com>
; Remarks .......: Works with floats as well as integers
; Example .......: MsgBox( 4096, "_Min() - Test", "_Min( 3.5, 10 ) = " & _Min( 3.5, 10 ) )
; ===============================================================================================================================
Func _Min($nNum1, $nNum2)
; Check to see if the parameters are indeed numbers of some sort.
If (Not IsNumber($nNum1)) Then Return SetError(1, 0, 0)
If (Not IsNumber($nNum2)) Then Return SetError(2, 0, 0)
If $nNum1 > $nNum2 Then
Return $nNum2
Else
Return $nNum1
EndIf
EndFunc ;==>_Min
; #FUNCTION# ====================================================================================================================
; Name...........: _Radian()
; Description ...: Converts degrees to radians.
; Syntax.........: _Radian( $nDegrees )
; Parameters ....: $nDegrees = Degrees to be converted into radians.
; Return values .: On Success: = Returns the radians converted from degrees.
; On Failure: = Returns a blank string.
; @ERROR: = 0 = No error.
; 1 = $nDegrees is not a number.
; Author ........: Erifash <erifash at gmail dot com>
; Remarks .......: In mathmatics and physics, the radian is a unit of
; angle measurement. One radian is approximately
; 57.2957795130823 degrees. To figure out that number,
; use the formula ( 180 / pi ). Because pi is used in
; the formula, the result is infinite in decimal places.
; The fact that AutoIt has a limited number of decimal
; places makes the result more innaccurate as you move
; down the decimal line. This is quite suitable for basic
; physics calculations though.
; Example .......: MsgBox(4096, "_Radian() Test", "_Radian( 35 ) = " & _Radian( 35 ))
; ===============================================================================================================================
Func _Radian($nDegrees)
If Number($nDegrees) Then Return $nDegrees / 57.2957795130823
Return SetError(1, 0, "")
EndFunc ;==>_Radian
蛋哥来点注释吧... 回复 9# 邪恶海盗
exe帮助里,不是原始带的那个 回复 10# netegg
全鸟文...{:face (319):}
蛋哥,我那个拆字符的问题到底咋整啊???{:face (382):} 回复 11# 邪恶海盗
哪个拆字符? 回复 12# netegg
这个帖:如何设置ListView指定列数据输出到Combox供选择??(点击查看)
主要功能代码贴上来了,帮我瞧瞧...
页:
[1]