Marc 'BlackJack' Rintsch wrote: > In <[EMAIL PROTECTED]>, Philippe Martin wrote: > >> I'm looking for an algo that would convert a list such as: >> >> I'm using python to prototype the algo: this will move to C in an >> embedded system where an int has 16 bits - I do not wish to use any >> python library. >> >> l1 = [1,2,3,4,6,7,8] #represents the decimal number 12345678 >> l2 = func (l1) >> # l2 = [0x1, 0x2, 0xD, 0x6, 0x8, 0x7] #represents 0x12D687 > > def func(x): > result = list(x) > result[2:4] = [0xd] > result[-1], result[-2] = result[-2], result[-1] > return result > > l1 = [1, 2, 3, 4, 6, 7, 8] > l2 = func(l1) > print l2 > > And now please describe you problem a little better. ;-) > > Ciao, > Marc 'BlackJack' Rintsch
I'll try. first of all python is not going to be used for my purpose (sigh) I have device A which holds a binary coded decimal array [N1,N2,....Nn] where the array represents a decimal number. In C: unsigned char dec[] = {1,2,3,4,5,6,7,8}; I need that array converted for device B into an array where each element represents the actual byte value. In C: the result would be unsigned char hex[] = {0x1,0x2,0xD,0x6,0x8,0x7}; I guess any pocket calculator goes through that process for dec/hex conversion. Hope that's clearer. Regards, Philippe -- http://mail.python.org/mailman/listinfo/python-list