So, for example, you'd be trying to concatenate the binary data
01010101 and 10101010, and get 0101010110101010? You can do that by
shifting the bits:
>>> (0b01010101 << 8) + 0b10101010
21930
which is equivalent to:
>>> 0b0101010110101010
21930
You can also do it with numerical data:
>>> 0b10101010
170
>>> 0b01010101
85
>>> (85 << 8) + 170
21930
>>> "{:b}".format((85 << 8) + 170)
'101010110101010'
On 24 April 2013 17:52, sparkle Plenty <[email protected]> wrote:
> What is the best way to concatenate packed numeric data? I am building a
> message to send to a device and it has a very specific header format and
> variable length payload. Converting to string, concatenating, and then
> converting back to numeric introduced errors. The tuple() function also
> introduced errors.
>
> The code is proprietary so I am not comfortable posting it. I have been
> programming in Python for a few weeks. It is my first OOP language. My
> background, in the dim and distant past, is mainframe.
>
> Any help would be greatly appreciated. Thank you in advance.
>
> _______________________________________________
> Tutor maillist - [email protected]
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
--
Robert K. Day
[email protected]
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor