[Baypiggies] Input in hex format

David Elsen elsen.david08 at gmail.com
Fri Aug 15 01:50:15 CEST 2008


Stephen,

I also want to parse the verilog syntax. I will work on your suggestion.
For now, Chris suggestion got me going. I can pass the hex input just with
0x..... to my class.

Thanks a lot for suggestion.
David

On Thu, Aug 14, 2008 at 4:26 PM, Stephen McInerney
<spmcinerney at hotmail.com>wrote:

> David,
>
> I did this a while back, it's not as trivial as it looks.
> Two subtle points:
>
> a) In general the result could be 64bits or greater (although your case is
> probably 32b).
> int(...,16) may sometimes return the full 64b result, but is better to
> explicitly
> write long(...,16).
> (And for anyone wanting to convert hex values >64b, I am not aware of any
> automatic way other than first chunking the result into 16-hex-digit
> subsequences (and see the next point), and returning say a tuple-of-longs).
>
> b) I was parsing Verilog syntax which also allows optional underscores
> inside hex numbers,
> usually by convention placed every four or eight hex characters from
> the RHS for human readability, e.g. "0xa_bcde_1234"
> For things like that you must first make a regex or string substitution
> (re.sub
> or the deprecated string.replace or string.translate)
> For constants >64b long, must do padding-character removal (b) before
> chunking it to do conversion (a).
>
> Best,
> Stephen
>
> ------------------------------
> Your PC, mobile phone, and online services work together like never before.
> See how Windows(R) fits your life<http://clk.atdmt.com/MRT/go/108587394/direct/01/>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20080814/718d0c25/attachment.htm>


More information about the Baypiggies mailing list