Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Blockly
    5. (erledigt) Bitweise "and" in Blockly

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    (erledigt) Bitweise "and" in Blockly

    This topic has been deleted. Only users with topic management privileges can see it.
    • ubecker
      ubecker last edited by ubecker

      Wie schreibt man in Blockly
      c= a and b
      Ich benötige ein bestimmtes Bit aus einem Wert.
      Beispiel :
      a ist 43
      b ist 2
      Ergebnis 2
      Beispiel:
      a ist 13
      b ist 2
      Ergebnis: 0

      Ich brauche nur das Bit 2
      oder geht das nur in JS?

      haus-automatisierung paul53 2 Replies Last reply Reply Quote 0
      • haus-automatisierung
        haus-automatisierung Developer Most Active @ubecker last edited by haus-automatisierung

        @ubecker Du meinst den &-Operator?

        43 ist 0010 1011
        02 ist 0000 0010
        ----------------
               0000 0010
        

        Wäre in JavaScript const c = 42 & 2. Kann man auch binär schreiben: const c = 0b101011 & 0b10.

        Einen Baustein gibts dafür aktuell nicht. Am einfachsten über eine selbst definierte Funktion:

        return param & 2; oder return param & 0b10;

        ubecker 1 Reply Last reply Reply Quote 0
        • ubecker
          ubecker @haus-automatisierung last edited by

          @haus-automatisierung said in Bitweise "and" in Blockly:

          Du meinst den &-Operator?

          ja genau.
          ok. Dan werde ich wohl alles in JS schreiben. Ist immer eine gute Übung.
          danke

          haus-automatisierung 1 Reply Last reply Reply Quote 0
          • haus-automatisierung
            haus-automatisierung Developer Most Active @ubecker last edited by

            @ubecker sagte in Bitweise "and" in Blockly:

            Dan werde ich wohl alles in JS schreiben.

            Kannst ja bei Blockly bleiben und einfach eine JS-Funktion mit einem Einzeiler erstellen.

            1 Reply Last reply Reply Quote 0
            • paul53
              paul53 @ubecker last edited by

              @ubecker sagte: Ich benötige ein bestimmtes Bit aus einem Wert.

              Siehe checkBit(val, bit)

              ubecker 1 Reply Last reply Reply Quote 0
              • ubecker
                ubecker @paul53 last edited by

                @paul53 said in Bitweise "and" in Blockly:

                @ubecker sagte: Ich benötige ein bestimmtes Bit aus einem Wert.

                Siehe checkBit(val, bit)

                Danke, gelesen und nicht alles verstanden. Ist noch etwas zu hoch für mich. (Bin Hardwerker und kein Softwerker)
                Hab aber eine einfache JS Lösung für mich gefunden.
                brauch doch nur 3 Bits.

                let Bit_0 = 1;
                let Bit_1 = 2;
                let Bit_2 = 4;
                let ID_WR2Haus = 'javascript.0.PV_WR2Haus';
                let ID_Batt_charge = 'javascript.0.PV_Batt_charge';
                let ID_Batt_discharge = 'javascript.0.PV_Batt_discharge';
                let ID_System_state = 'alias.0.Energie.PV_Anlage.Betriebsstatus';
                let System_state = getState(ID_System_state).val;
                let Batt_charge = getState(ID_Batt_charge).val;
                let WR2Haus = getState(ID_WR2Haus).val;
                
                // 0 = not charging ; 2 = Charging; 
                setState(ID_Batt_charge , (System_state & Bit_1), true);
                // 0 = not discharging ; 4 = discharging; 
                setState(ID_Batt_discharge , (System_state & Bit_2), true);
                 // 0 = no Power from PV; 1 = power from PV
                setState(ID_WR2Haus , (System_state & Bit_1), true);
                
                on({ id: [].concat(ID_System_state), change: 'ne' }, async (obj) => {
                  let value = obj.state.val;
                  let oldValue = obj.oldState.val;
                  System_state = (obj.state ? obj.state.val : '');
                  setState(ID_Batt_charge , (System_state & Bit_1), true);
                  setState(ID_Batt_discharge , (System_state & Bit_2), true);
                  setState(ID_WR2Haus , (System_state & Bit_0), true);
                });
                
                
                
                1 Reply Last reply Reply Quote 0
                • First post
                  Last post

                Support us

                ioBroker
                Community Adapters
                Donate

                873
                Online

                31.9k
                Users

                80.2k
                Topics

                1.3m
                Posts

                3
                6
                390
                Loading More Posts
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes
                Reply
                • Reply as topic
                Log in to reply
                Community
                Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                The ioBroker Community 2014-2023
                logo