Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #10910

Re: problem with bcd and a number

From Peter Otten <__peter__@web.de>
Subject Re: problem with bcd and a number
Date 2011-08-05 17:52 +0200
Organization None
References <a59a0314-4fab-4a57-a648-daa2570f2f94@v7g2000vbk.googlegroups.com> <4E3AF2FA.7000207@ieee.org> <CAC6CgJ9QRRe+OU=RG+cK0NJuwdQw07qjR-Du98gi4O+NRicQ6A@mail.gmail.com> <CAGGBd_owY1Jyb40nw29zwQDcFu+UrfCnWBLY-J9KGnzsbLvugg@mail.gmail.com> <CAPTjJmpHtUT0tKX0WYxjZdTvxHaW4wt5hBn0i4gJc4KeEqfpnQ@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1929.1312559562.1164.python-list@python.org> (permalink)

Show all headers | View raw


Chris Angelico wrote:

> On Fri, Aug 5, 2011 at 1:40 AM, Dan Stromberg <drsalists@gmail.com> 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
>>> int("\x12\x34\x56".encode("hex"))
123456

> It's probably better to just do the bitwise operations though.

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


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