BCD列表到HEX列表 [英] BCD List to HEX List

查看:51
本文介绍了BCD列表到HEX列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在寻找一个可以转换列表的算法,例如:


我正在使用用于原型算法的python:这将转移到嵌入式
系统中的C,其中int有16位 - 我不想使用任何python库。


l1 = [1,2,3,4,6,7,8]#表示十进制数12345678

l2 = func(l1)

#l2 = [0x1,0x2,0xD,0x6,0x8,0x7] #represents 0x12D687

问候,


Philippe

Hi,

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
Regards,

Philippe

推荐答案

在< 5S8zg.1553
In <5S8zg.1553


W93.658@dukeread05> ;, Philippe Martin写道:
W93.658@dukeread05>, Philippe Martin wrote:

我正在寻找能够转换列表的算法,例如:


我正在使用python来构建算法原型:这将会移动在嵌入式
系统中,C为16位 - 我不希望使用任何python库。


l1 = [1,2, 3,4,6,7,8]#表示t十进制数12345678

l2 = func(l1)

#l2 = [0x1,0x2,0xD,0x6,0x8,0x7] #represents 0x12D687
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]

结果[-1],结果[-2] =结果[-2],结果[-1]

返回结果


l1 = [1,2,3,4,6,7,8]

l2 = func(l1)

print l2

>
现在请把问题描述得更好一些。 ;-)


Ciao,

Marc''BlackJack''Rintsch

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


Marc'' BlackJack''Rintsch写道:
Marc ''BlackJack'' Rintsch wrote:

In< 5S8zg.1553
In <5S8zg.1553


这篇关于BCD列表到HEX列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆