Oct-25-2017, 04:07 AM
Thanks for taking the time to reply.
After reviewing the replies and reading some documentation I have come up with another snippet. This code isn't the most Pythonic but should be easy to understand.
After reviewing the replies and reading some documentation I have come up with another snippet. This code isn't the most Pythonic but should be easy to understand.
>>> def integer_list_to_byte(integer_list): control_byte = 0 for element in integer_list: control_byte += pow(2, element- 1) return control_byte >>> integer_list_to_byte([1, 3, 4, 7]) 77Alternatively, using the shift operator:
>>> def integer_list_to_byte(integer_list): control_byte = 0 for element in integer_list: control_byte += 1 << (element- 1) return control_byte >>> integer_list_to_byte([1, 3, 4, 7]) 77Is there any difference in execution speed?