Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #10870
| Date | 2011-08-04 15:28 -0400 |
|---|---|
| From | Dave Angel <davea@ieee.org> |
| Subject | Re: problem with bcd and a number |
| References | <a59a0314-4fab-4a57-a648-daa2570f2f94@v7g2000vbk.googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1899.1312486154.1164.python-list@python.org> (permalink) |
On 01/-10/-28163 02:59 PM, nephish wrote: > Hey all, > > I have been trying to get my head around how to do something, but i am > missing how to pull it off. > I am reading a packet from a radio over a serial port. > > i have " two bytes containing the value i need. The first byte is the > LSB, second is MSB. Both bytes are BCD-encoded, with the LSB > containing digits zX and MSB containing digits xy. The system speed > is then xyz%, where 100% means maximum speed and would be given by > bytes 00(LSB) 10(MSB)." > > that is a quote from the documentation. > Anyway, i am able to parse out the two bytes i need, but don't know > where to go from there. > > thanks for any tips on this. > Your problem is simply to extract the two nibbles from a byte. Then you can use trivial arithmetic to combine the nibbles. Error checking is another matter. First you need to specify whether this is Python 2.x or Python 3.x. In this message I'll assume 2.7 >>> val = "\x47" >>> print val G >>> print ord(val) 71 >>> print ord(val)/16 4 >>> print ord(val)%16 7 >>> DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
problem with bcd and a number nephish <nephish@gmail.com> - 2011-08-04 11:31 -0700 Re: problem with bcd and a number Dave Angel <davea@ieee.org> - 2011-08-04 15:28 -0400 Re: problem with bcd and a number Christoph Hansen <ch@radamanthys.de> - 2011-08-04 21:31 +0200 Re: problem with bcd and a number Chris Angelico <rosuav@gmail.com> - 2011-08-05 16:32 +0100 Re: problem with bcd and a number Peter Otten <__peter__@web.de> - 2011-08-05 17:52 +0200
csiph-web