Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #35462
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python.list@tim.thechases.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'python': 0.09; '16)': 0.09; 'encode': 0.09; 'subject:string': 0.09; 'cc:addr:python- list': 0.10; '-tkc': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'hex': 0.16; 'integer.': 0.16; 'message-id:@tim.thechases.com': 0.16; 'received:70.251': 0.16; 'received:dsl.rcsntx.swbell.net': 0.16; 'received:rcsntx.swbell.net': 0.16; 'received:swbell.net': 0.16; 'roy': 0.16; 'subject:raw': 0.16; 'wrote:': 0.17; 'integer': 0.17; 'string,': 0.17; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'pass': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'wondering': 0.26; 'assert': 0.29; 'long.': 0.29; "i'm": 0.29; 'you?': 0.32; 'built- in': 0.35; 'subject:?': 0.35; 'something': 0.35; 'but': 0.36; 'subject:: ': 0.38; 'some': 0.38; 'gives': 0.39; 'end': 0.40; 'back': 0.62; 'smith': 0.71; 'directly.': 0.78; '2.7.': 0.84; 'received:50.22': 0.84 |
| Date | Mon, 24 Dec 2012 09:58:01 -0600 |
| From | Tim Chase <python.list@tim.thechases.com> |
| User-Agent | Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111120 Icedove/3.1.16 |
| MIME-Version | 1.0 |
| To | Roy Smith <roy@panix.com> |
| Subject | Re: Integer as raw hex string? |
| References | <roy-88A3B9.10360324122012@news.panix.com> |
| In-Reply-To | <roy-88A3B9.10360324122012@news.panix.com> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | 7bit |
| X-AntiAbuse | This header was added to track abuse, please include it with any abuse report |
| X-AntiAbuse | Primary Hostname - boston.accountservergroup.com |
| X-AntiAbuse | Original Domain - python.org |
| X-AntiAbuse | Originator/Caller UID/GID - [47 12] / [47 12] |
| X-AntiAbuse | Sender Address Domain - tim.thechases.com |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1256.1356364625.29569.python-list@python.org> (permalink) |
| Lines | 30 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1356364625 news.xs4all.nl 6976 [2001:888:2000:d::a6]:50427 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:35462 |
Show key headers only | View raw
On 12/24/12 09:36, Roy Smith wrote:
> I have an integer that I want to encode as a hex string, but I don't
> want "0x" at the beginning, nor do I want "L" at the end if it happened
> to be a long. The result needs to be something I can pass to int(h, 16)
> to get back my original integer.
>
> The brute force way works:
>
> h = hex(i)
> assert h.startswith('0x')
> h = h[2:]
> if h.endswith('L'):
> h = h[:-1]
>
> but I'm wondering if there's some built-in call which gives me what I
> want directly. Python 2.7.
Would something like
h = "%08x" % i
or
h = "%x" % i
work for you?
-tkc
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Integer as raw hex string? Roy Smith <roy@panix.com> - 2012-12-24 10:36 -0500
Re: Integer as raw hex string? Tim Chase <python.list@tim.thechases.com> - 2012-12-24 09:58 -0600
Re: Integer as raw hex string? Roy Smith <roy@panix.com> - 2012-12-24 11:21 -0500
Re: Integer as raw hex string? MRAB <python@mrabarnett.plus.com> - 2012-12-24 18:15 +0000
csiph-web