bit concatenate
-
hello,
i would like to concatenate 4 sensor values to create bytes to send via sigfox.
exemple :
capt1 =0b1001010001110010101110
capt2=0b10111011101111101001110
capt3=0b0
capt4=0b1010010i 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 resultand the error :
TypeError: unsupported types for : 'str', 'int'on this line :
temp = ((capt1 << 23) | capt2)thank you
-
@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``` -
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.
-
This post is deleted! -
See also the BitString module for MicroPython.
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