• Hi,

    habe eben meine ersten Versuche entdeckt, dezimale in binäre Zahlen umzuwandeln. Rausgekommen ist eine Uhr mit Radiobuttons :)

    Leider hab ich irgendwann die "dec2bin()"-Funktion ausgewechselt, ist also nicht mehr ganz original nur von mir :(

    Spoiler anzeigen
    [autoit]

    ;binary clock

    [/autoit] [autoit][/autoit] [autoit]

    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    $Form1_1 = GUICreate("Binary Clock", 504, 114, 192, 114)
    GUIStartGroup()
    $H16 = GUICtrlCreateRadio("", 16, 56, 17, 17)
    GUIStartGroup()
    GUICtrlSetState(-1,$gui_disable)
    $H8 = GUICtrlCreateRadio("", 40, 56, 17, 17)
    GUIStartGroup()
    GUICtrlSetState(-1,$gui_disable)
    $H4 = GUICtrlCreateRadio("", 64, 56, 17, 17)
    GUIStartGroup()
    GUICtrlSetState(-1,$gui_disable)
    $H2 = GUICtrlCreateRadio("", 88, 56, 17, 17)
    GUIStartGroup()
    GUICtrlSetState(-1,$gui_disable)
    $H1 = GUICtrlCreateRadio("", 112, 56, 17, 17)
    GUICtrlSetState(-1,$gui_disable)

    [/autoit] [autoit][/autoit] [autoit]

    $Label1 = GUICtrlCreateLabel("16 8 4 2 1", 16, 40, 109, 17)
    $Label2 = GUICtrlCreateLabel("Stunden", 50, 16, 51, 17)
    GUICtrlSetFont(-1, 8, 800, 4, "MS Sans Serif")

    [/autoit] [autoit][/autoit] [autoit]

    GUIStartGroup()
    $M32 = GUICtrlCreateRadio("", 168, 56, 17, 17)
    GUICtrlSetState(-1,$gui_disable)
    GUIStartGroup()
    $M16 = GUICtrlCreateRadio("", 192, 56, 17, 17)
    GUICtrlSetState(-1,$gui_disable)
    GUIStartGroup()
    $M8 = GUICtrlCreateRadio("", 216, 56, 17, 17)
    GUICtrlSetState(-1,$gui_disable)
    GUIStartGroup()
    $M4 = GUICtrlCreateRadio("", 240, 56, 17, 17)
    GUICtrlSetState(-1,$gui_disable)
    GUIStartGroup()
    $M2 = GUICtrlCreateRadio("", 264, 56, 17, 17)
    GUICtrlSetState(-1,$gui_disable)
    GUIStartGroup()
    $M1 = GUICtrlCreateRadio("", 288, 56, 17, 17)
    GUICtrlSetState(-1,$gui_disable)

    [/autoit] [autoit][/autoit] [autoit]

    $Label3 = GUICtrlCreateLabel("32 16 8 4 2 1", 168, 40, 133, 17)
    $Label4 = GUICtrlCreateLabel("Minuten", 200, 16, 49, 17)
    GUICtrlSetFont(-1, 8, 800, 4, "MS Sans Serif")
    $Label8 = GUICtrlCreateLabel("°", 144, 56, 15, 17)
    GUICtrlSetFont(-1, 25, 400, 0, "MS Sans Serif")
    $Label7 = GUICtrlCreateLabel("°", 144, 32, 15, 17)
    GUICtrlSetFont(-1, 25, 400, 0, "MS Sans Serif")

    [/autoit] [autoit][/autoit] [autoit]

    GUIStartGroup()
    $S32 = GUICtrlCreateRadio("", 344, 56, 17, 17)
    GUICtrlSetState(-1,$gui_disable)
    GUIStartGroup()
    $S16 = GUICtrlCreateRadio("", 368, 56, 17, 17)
    GUICtrlSetState(-1,$gui_disable)
    GUIStartGroup()
    $S8 = GUICtrlCreateRadio("", 392, 56, 17, 17)
    GUICtrlSetState(-1,$gui_disable)
    GUIStartGroup()
    $S4 = GUICtrlCreateRadio("", 416, 56, 17, 17)
    GUICtrlSetState(-1,$gui_disable)
    GUIStartGroup()
    $S2 = GUICtrlCreateRadio("", 440, 56, 17, 17)
    GUICtrlSetState(-1,$gui_disable)
    GUIStartGroup()
    $S1 = GUICtrlCreateRadio("", 464, 56, 17, 17)
    GUICtrlSetState(-1,$gui_disable)

    [/autoit] [autoit][/autoit] [autoit]

    $Label9 = GUICtrlCreateLabel("32 16 8 4 2 1", 344, 40, 133, 17)
    $Label10 = GUICtrlCreateLabel("Sekunden", 370, 16, 61, 17)
    GUICtrlSetFont(-1, 8, 800, 4, "MS Sans Serif")
    $Label12 = GUICtrlCreateLabel("°", 320, 56, 15, 25)
    GUICtrlSetFont(-1, 25, 400, 0, "MS Sans Serif")
    $Label13 = GUICtrlCreateLabel("°", 320, 32, 15, 25)
    GUICtrlSetFont(-1, 25, 400, 0, "MS Sans Serif")

    [/autoit] [autoit][/autoit] [autoit]

    $Label5 = GUICtrlCreateLabel("", 65, 80, 42, 17)
    $Label6 = GUICtrlCreateLabel("", 216, 80, 42, 17)
    $Label11 = GUICtrlCreateLabel("", 392, 80, 42, 17)

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit]

    dim $hour, $minute, $second

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit

    [/autoit] [autoit][/autoit] [autoit]

    EndSwitch

    [/autoit] [autoit][/autoit] [autoit]

    dobinary()

    [/autoit] [autoit][/autoit] [autoit]

    GUICtrlSetData($label11,@SEC)
    GUICtrlSetData($label5,@HOUR)
    GUICtrlSetData($label6,@MIN)

    [/autoit] [autoit][/autoit] [autoit]

    sleep(90)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    func dobinary()
    $hour = @HOUR
    $minute = @MIN
    $second = @SEC

    [/autoit] [autoit][/autoit] [autoit]

    if $hour > 0 Then $hour = dec2bin($hour)
    if $hour = 0 then $hour = "00000"

    [/autoit] [autoit][/autoit] [autoit]

    if $minute > 0 Then $minute = dec2bin($minute)
    if $minute = 0 then $minute = "000000"

    [/autoit] [autoit][/autoit] [autoit]

    if $second > 0 Then $second = dec2bin($second)
    if $second = 0 then $second = "000000"

    [/autoit] [autoit][/autoit] [autoit]

    setbinh($hour)
    setbinm($minute)
    setbins($second)

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    func setbins($second)
    local $arys[6]
    for $i = 1 to UBound($arys)
    $arys[$i-1] = StringMid($second,$i,1)
    Next
    if $arys[0] = 0 then GUICtrlSetState($S32,$GUI_UNCHECKED)
    if $arys[0] = 1 then GUICtrlSetState($S32,$GUI_CHECKED)
    if $arys[1] = 0 then GUICtrlSetState($S16,$GUI_UNCHECKED)
    if $arys[1] = 1 then GUICtrlSetState($S16,$GUI_CHECKED)
    if $arys[2] = 0 then GUICtrlSetState($S8,$GUI_UNCHECKED)
    if $arys[2] = 1 then GUICtrlSetState($S8,$GUI_CHECKED)
    if $arys[3] = 0 then GUICtrlSetState($S4,$GUI_UNCHECKED)
    if $arys[3] = 1 then GUICtrlSetState($S4,$GUI_CHECKED)
    if $arys[4] = 0 then GUICtrlSetState($S2,$GUI_UNCHECKED)
    if $arys[4] = 1 then GUICtrlSetState($S2,$GUI_CHECKED)
    if $arys[5] = 0 then GUICtrlSetState($S1,$GUI_UNCHECKED)
    if $arys[5] = 1 then GUICtrlSetState($S1,$GUI_CHECKED)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    func setbinm($minute)
    local $arym[6]
    for $i = 1 to UBound($arym)
    $arym[$i-1] = StringMid($minute,$i,1)
    Next
    if $arym[0] = 0 then GUICtrlSetState($M32,$GUI_UNCHECKED)
    if $arym[0] = 1 then GUICtrlSetState($M32,$GUI_CHECKED)
    if $arym[1] = 0 then GUICtrlSetState($M16,$GUI_UNCHECKED)
    if $arym[1] = 1 then GUICtrlSetState($M16,$GUI_CHECKED)
    if $arym[2] = 0 then GUICtrlSetState($M8,$GUI_UNCHECKED)
    if $arym[2] = 1 then GUICtrlSetState($M8,$GUI_CHECKED)
    if $arym[3] = 0 then GUICtrlSetState($M4,$GUI_UNCHECKED)
    if $arym[3] = 1 then GUICtrlSetState($M4,$GUI_CHECKED)
    if $arym[4] = 0 then GUICtrlSetState($M2,$GUI_UNCHECKED)
    if $arym[4] = 1 then GUICtrlSetState($M2,$GUI_CHECKED)
    if $arym[5] = 0 then GUICtrlSetState($M1,$GUI_UNCHECKED)
    if $arym[5] = 1 then GUICtrlSetState($M1,$GUI_CHECKED)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    func setbinh($hour)
    local $aryh[6]
    for $i = 1 to UBound($aryh)
    $aryh[$i-1] = StringMid($hour,$i,1)
    Next
    ;~ if $aryh[0] = 0 then GUICtrlSetState($H32,$GUI_UNCHECKED)
    ;~ if $aryh[0] = 1 then GUICtrlSetState($H32,$GUI_CHECKED)
    if $aryh[1] = 0 then GUICtrlSetState($H16,$GUI_UNCHECKED)
    if $aryh[1] = 1 then GUICtrlSetState($H16,$GUI_CHECKED)
    if $aryh[2] = 0 then GUICtrlSetState($H8,$GUI_UNCHECKED)
    if $aryh[2] = 1 then GUICtrlSetState($H8,$GUI_CHECKED)
    if $aryh[3] = 0 then GUICtrlSetState($H4,$GUI_UNCHECKED)
    if $aryh[3] = 1 then GUICtrlSetState($H4,$GUI_CHECKED)
    if $aryh[4] = 0 then GUICtrlSetState($H2,$GUI_UNCHECKED)
    if $aryh[4] = 1 then GUICtrlSetState($H2,$GUI_CHECKED)
    if $aryh[5] = 0 then GUICtrlSetState($H1,$GUI_UNCHECKED)
    if $aryh[5] = 1 then GUICtrlSetState($H1,$GUI_CHECKED)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func dec2bin($Decimal, $MaxLen=10, $DontAddLeadingZeros=False, $ErrorOnMoreThanOneByte=True)
    $Decimal = $Decimal + 1
    If $Decimal > 256 And $ErrorOnMoreThanOneByte = True Then
    SetError(1)
    Return ''
    EndIf
    Local $Binary = ''
    For $i = $MaxLen To 0 Step -1
    Local $TempVar1 = $Decimal - (2^$i)
    If $TempVar1 <= 0 Then
    $Binary &= '0'
    Else
    $Decimal -= 2^$i
    $Binary &= '1'
    EndIf
    Next
    Do
    Local $TempVar2 = StringLeft($Binary, 1)
    If $TempVar2 = 0 Then
    $Binary = StringTrimLeft($Binary, 1)
    EndIf
    Until $TempVar2 = 1
    Local $TempVar3 = StringLen($Binary)
    Local $TempVar4 = ''
    If $TempVar3 < 6 And $DontAddLeadingZeros = False Then
    For $i = $TempVar3+1 To 6 Step 1
    $TempVar4 &= '0'
    Next
    $Binary = $TempVar4 & $Binary
    ElseIf $TempVar3 > 6 And $ErrorOnMoreThanOneByte = True Then
    SetError(1)
    Return ''
    EndIf
    Return $Binary
    EndFunc

    [/autoit]

    Gruß
    x0r

    Simon nörgelt, Simon nervt - aber Simon verbessert die Welt. Glaubt er.

  • Das ist meine _DecToBin.

    Spoiler anzeigen
    [autoit]

    Func _DecToBin($_iDec, $_xAddZero = True, $_iMaxLen = 8)
    Local $_sBin, $_iLen
    Do
    $_sBin = Mod($_iDec, 2) & $_sBin
    $_iDec = Floor($_iDec / 2)
    Until $_iDec = 0
    If Not $_xAddZero Then Return $_sBin
    $_iLen = StringLen(Hex($_iDec, Ceiling($_iMaxLen/4))) * 4
    For $i = 1 To $_iLen - 1
    $_sBin = "0" & $_sBin
    Next
    Return StringRight($_sBin, $_iLen)
    EndFunc ;==>_DecToBin

    [/autoit]