Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    bit concatenate

    Scheduled Pinned Locked Moved Discussion
    5 Posts 4 Posters 383 Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Q Offline
      quentho
      last edited by

      hello,

      i would like to concatenate 4 sensor values to create bytes to send via sigfox.

      exemple :
      capt1 =0b1001010001110010101110
      capt2=0b10111011101111101001110
      capt3=0b0
      capt4=0b1010010

      i would like :
      temp=0b1001010001110010101110 10111011101111101001110 0 1010010
      (capt1) (capt2) (capt3) (capt4)

      i try with two but it's not working

      this is my code :

      class tools:
      
          def trame(capt1,capt2,capt3,capt4):
      
              temp = ((capt1 << 23) | capt2)
              print(capt1)
              print(capt2)
              result=hex(temp)
              return  result
      
      

      and the error :

      TypeError: unsupported types for : 'str', 'int'
      

      on this line :

      temp = ((capt1 << 23) | capt2)
      

      thank you

      E robert-hhR 2 Replies Last reply Reply Quote 0
      • E Offline
        Emmanuel Florent @quentho
        last edited by Emmanuel Florent

        @quentho you can try with:

        def trame(capt1,capt2,capt3,capt4):
                result = (capt1 << 22) | capt2
                result = (result << 1 ) | capt3
                result = (result << 7) | capt4
                return  result```
        1 Reply Last reply Reply Quote 0
        • Q Offline
          quentho
          last edited by

          I resolve my probleme, it was the bin function that returns a string of characters and not a binary number

          thank you for your answer.

          1 Reply Last reply Reply Quote 0
          • robert-hhR Offline
            robert-hh @quentho
            last edited by

            This post is deleted!
            1 Reply Last reply Reply Quote 0
            • rcolisteteR Offline
              rcolistete
              last edited by

              See also the BitString module for MicroPython.

              My "MicroPython Samples". My "MicroPython Firmwares" with many options (double precision, ulab, etc).

              1 Reply Last reply Reply Quote 0

              Hello! It looks like you're interested in this conversation, but you don't have an account yet.

              Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

              With your input, this post could be even better 💗

              Register Login
              • 1 / 1
              • First post
                Last post

              Pycom on Twitter

              Pycom