小编Pab*_* P.的帖子

Python - 十进制到整数低字节然后是高字节

您好我是Python的新手,但我对它感兴趣已有2年了.我想制造机器人,我正在尝试pyserial在搅拌机上使用Python .但是我发现了一个问题,在谷歌和这个网站上寻找答案2个小时之后,我发现也许我迟钝了,因为我无法解决它.我想还没问.

我正在使用devantech sd84伺服控制器并通过USB端口控制它,这是我使用的串行设备pyserial.问题是我希望Python在用户输入之间取一个十进制值400- 2200我知道如何做但我需要Python将它显示为两个字节并先发送低字节然后再发送高字节.例如(伪代码,因为我不知道如何编程):

    #ask for a decimal number between a range (the range does not really matters)
    x = raw_input('\tInsert a number between 400-2200:') #Insert a number between 400-2200: 1500
    #show it as hex
    hex(x) #5dc
    #put it in two bytes and in this case add a zero(?) I don't know how to do that.
    0xDC 0x05
    #add it to a 16-bit integer to send it to the servo …
Run Code Online (Sandbox Code Playgroud)

python hex byte integer decimal

2
推荐指数
1
解决办法
4052
查看次数

标签 统计

byte ×1

decimal ×1

hex ×1

integer ×1

python ×1