Re: problem with bcd and a number

2011-08-05 Thread Peter Pearson
On Thu, 04 Aug 2011 21:52:45 +0200, Christoph Hansen wrote: > MRAB schrieb: > >> The value is MSB * 100 + (LSB>> 4) * 10 + (LSB& 0xF) > > i would say > > (MSB >> 4)*100 + (MSB & 0xF)*10 + (LSB >> 4) > > but who knows I concur. I think the documentation is trying to say that the low-order nibb

Re: problem with bcd and a number

2011-08-05 Thread Peter Otten
Chris Angelico wrote: > On Fri, Aug 5, 2011 at 1:40 AM, Dan Stromberg wrote: > print int(hex(0x72).replace('0x', '')) >> 72 > > Or simpler: int(hex(0x72)[2:]) > > Although if you have it as a string, you need to ord() the string. Or use str.encode(): >>> int("\x72".encode("hex")) 72 >>> i

Re: problem with bcd and a number

2011-08-05 Thread Chris Angelico
On Fri, Aug 5, 2011 at 1:40 AM, Dan Stromberg wrote: print int(hex(0x72).replace('0x', '')) > 72 Or simpler: int(hex(0x72)[2:]) Although if you have it as a string, you need to ord() the string. It's probably better to just do the bitwise operations though. ChrisA -- http://mail.python.o

Re: problem with bcd and a number

2011-08-04 Thread Dan Stromberg
It sounds like you have what you need, but here's an amusing way of dealing with a BCD byte: >>> print int(hex(0x72).replace('0x', '')) 72 On Thu, Aug 4, 2011 at 5:15 PM, shawn bright wrote: > Thanks for your help on this, gents. Got it working now. > shawn > > On Thu, Aug 4, 2011 at 2:28 PM, D

Re: problem with bcd and a number

2011-08-04 Thread shawn bright
Thanks for your help on this, gents. Got it working now. shawn On Thu, Aug 4, 2011 at 2:28 PM, Dave Angel wrote: > nibbles from a byte -- http://mail.python.org/mailman/listinfo/python-list

Re: problem with bcd and a number

2011-08-04 Thread Ethan Furman
MRAB wrote: On 04/08/2011 19:26, 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

Re: problem with bcd and a number

2011-08-04 Thread Christoph Hansen
MRAB schrieb: The value is MSB * 100 + (LSB>> 4) * 10 + (LSB& 0xF) i would say (MSB >> 4)*100 + (MSB & 0xF)*10 + (LSB >> 4) but who knows -- http://mail.python.org/mailman/listinfo/python-list

Re: problem with bcd and a number

2011-08-04 Thread MRAB
On 04/08/2011 19:26, 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

Re: problem with bcd and a number

2011-08-04 Thread Christoph Hansen
nephish schrieb: thanks for any tips on this. I'll try. In BCD a (decimal) digit is stored in a halfbyte (or a 'nibble'). So, in a byte you can store two decimal digits. For instance 42 would be nibble1 nibble2 0100 0010 42 >>> c=0b0110 >>> c 66 >>> c >> 4

Re: problem with bcd and a number

2011-08-04 Thread Ethan Furman
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-encode

Re: problem with bcd and a number

2011-08-04 Thread Dave Angel
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.

problem with bcd and a number

2011-08-04 Thread nephish
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 c

problem with bcd and a number

2011-08-04 Thread nephish
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 c