Hallo Community
weil mir langweilig war, hab ich mal einen Converter von Dual- zu Dezimalsystem und umgekehrt gemacht...vllt kanns ja jemand brauchen
UDF
; #FUNCTION# ======================================================================================
; Name ..........: _Dual_Dec2Dual()
; Description ...: This function converts an integer to a number in the dualsystem
; Syntax ........: _Dual_Dec2Dual($iInt)
; Parameters ....: $iInt - A Integer
; Return values .: Success
; |Returns a Number in the Dualsystem
; Failure
; |Set Errorcode 1
; Author ........: GE IXI TIM
; Link ..........: http://www.autoIt.de
; =================================================================================================
Func _Dual_Dec2Dual($iInt)
If Not IsInt($iInt) Then SetError(1, 0, 0)
Local $aNum[25], $iStart = 1, $aDual[25] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], $iEnd
Local $iLeft = 0
$aNum[0] = 1
For $i = 1 To 24
$iStart *= 2
$aNum[$i] = $iStart
Next
;_ArrayDisplay($aNum)
For $i = 24 To 0 Step -1
If $iInt >= $aNum[$i] Then
;MsgBox(64, "", $iInt & "-" & $aNum[$i] & " " & $i)
$aDual[24 - $i] = 1
$iInt -= $aNum[$i]
EndIf
Next
For $i = 0 To UBound($aDual) - 1
If $aDual[$i] = 1 Then ExitLoop
If $aDual[$i] = 0 Then $aDual[$i] = ""
Next
For $i = 0 To UBound($aDual) - 1
$iEnd &= $aDual[$i]
Next
Return $iEnd
EndFunc
; #FUNCTION# ======================================================================================
; Name ..........: _Dual_Dual2Dec()
; Description ...: This funktion converts a number in dualsystem to an integer
; Syntax ........: _Dual_Dual2Dec($iDual)
; Parameters ....: $iDual - a number in dualsystem
; Return values .: Success
; |Returns a integer
; Failure
; |Set errorcode 1
; Author ........: GE IXI TIM
; Link ..........: http://www.autoit.de
; =================================================================================================
Func _Dual_Dual2Dec($iDual)
If Not IsInt($iDual) Then SetError(1, 0, 0)
Local $aNum[25], $iStart = 1, $aZif, $iEnd
$aNum[0] = 1
For $i = 1 To 24
$iStart *= 2
$aNum[$i] = $iStart
Next
$aZif = StringSplit($iDual, "")
For $i = $aZif[0] To 1 Step -1
If $aZif[$i] = 1 Then $iEnd += $aNum[$aZif[0] - $i]
Next
Return $iEnd
EndFunc
UDF mit Beispiel
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$hGUI = GUICreate("_Dual Beispiel", 291, 85, 433, 187)
$decdual = GUICtrlCreateRadio("Dezimal zu Dual", 8, 8, 97, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$dualdec = GUICtrlCreateRadio("Dual zu Dezimal", 112, 8, 97, 17)
$Label1 = GUICtrlCreateLabel("Dezimal:", 8, 32, 44, 17)
$Label2 = GUICtrlCreateLabel("Dual:", 8, 56, 29, 17)
$inDEZ = GUICtrlCreateInput("", 56, 32, 225, 21)
$inDUAL = GUICtrlCreateInput("", 56, 56, 225, 21)
GUICtrlSetState(-1, $GUI_DISABLE)
$convert = GUICtrlCreateButton("Convert", 208, 0, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
case $decdual
If BitAND(GUICtrlRead($decdual), $GUI_CHECKED) = $GUI_CHECKED Then
GUICtrlSetState($inDEZ, $gui_ENABLE)
GUICtrlSetState($inDUAL, $GUI_DISABLE)
EndIf
Case $dualdec
If BitAND(GUICtrlRead($dualdec), $GUI_CHECKED) = $GUI_CHECKED Then
GUICtrlSetState($inDUAL, $gui_ENABLE)
GUICtrlSetState($inDEZ, $GUI_DISABLE)
EndIf
Case $convert
If BitAND(GUICtrlRead($decdual), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetData($inDUAL, _Dual_Dec2Dual(GUICtrlRead($inDEZ)))
If BitAND(GUICtrlRead($dualdec), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetData($inDEZ, _Dual_Dual2Dec(GUICtrlRead($inDUAL)))
EndSwitch
WEnd
Func _Dual_Dec2Dual($iInt)
If Not IsInt($iInt) Then SetError(1, 0, 0)
Local $aNum[25], $iStart = 1, $aDual[25] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], $iEnd
Local $iLeft = 0
$aNum[0] = 1
For $i = 1 To 24
$iStart *= 2
$aNum[$i] = $iStart
Next
;_ArrayDisplay($aNum)
For $i = 24 To 0 Step -1
If $iInt >= $aNum[$i] Then
;MsgBox(64, "", $iInt & "-" & $aNum[$i] & " " & $i)
$aDual[24 - $i] = 1
$iInt -= $aNum[$i]
EndIf
Next
For $i = 0 To UBound($aDual) - 1
If $aDual[$i] = 1 Then ExitLoop
If $aDual[$i] = 0 Then $aDual[$i] = ""
Next
For $i = 0 To UBound($aDual) - 1
$iEnd &= $aDual[$i]
Next
Return $iEnd
EndFunc
Func _Dual_Dual2Dec($iDual)
If Not IsInt($iDual) Then SetError(1, 0, 0)
Local $aNum[25], $iStart = 1, $aZif, $iEnd
$aNum[0] = 1
For $i = 1 To 24
$iStart *= 2
$aNum[$i] = $iStart
Next
$aZif = StringSplit($iDual, "")
For $i = $aZif[0] To 1 Step -1
If $aZif[$i] = 1 Then $iEnd += $aNum[$aZif[0] - $i]
Next
Return $iEnd
EndFunc