Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. XOR über Byte Array - wie?

    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

    XOR über Byte Array - wie?

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

      hat jemand hier evtl. eine elegante Funktion parat welche mir über 4 Byte in einem Array ein XOR berechnen kann? Also: 02 XOR 11 XOR 4F XOR 12?
      Das Array schaut aktuell so aus: ['02','11','4F','12']

      UncleSam paul53 2 Replies Last reply Reply Quote 0
      • UncleSam
        UncleSam Developer @spaceduck last edited by

        @spaceduck Sind die Werte wirklich Strings? Wenn ja, musst du für jeden einzelnen zuerst parseInt(x, 16) machen, danach kannst du einfach ^ verwenden, das ist XOR in JavaScript.

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

          @spaceduck sagte in XOR über Byte Array:

          Das Array schaut aktuell so aus: ['02','11','4F','12']

          var arr = ['02','11','4F','12'];
          var xor = parseInt(arr[0], 16);
          for(let i = 1; i < arr.length; i++) {
              xor = xor ^ parseInt(arr[i], 16);
          }
          log(xor.toString(16));
          
          S 1 Reply Last reply Reply Quote 1
          • S
            spaceduck @paul53 last edited by

            @paul53
            Danke, funzt einwandfrei!

            1 Reply Last reply Reply Quote 0
            • First post
              Last post

            Support us

            ioBroker
            Community Adapters
            Donate

            570
            Online

            31.8k
            Users

            80.0k
            Topics

            1.3m
            Posts

            javascript
            3
            4
            321
            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