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


Groups > comp.lang.python > #46535

Re: How to get an integer from a sequence of bytes

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ned@nedbatchelder.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.036
X-Spam-Evidence '*H*': 0.93; '*S*': 0.00; 'bytes,': 0.09; 'subject:How': 0.10; 'cc:addr:python-list': 0.11; '10:45': 0.16; 'received:74.55.86': 0.16; 'received:74.55.86.74': 0.16; 'received:smtp.webfaction.com': 0.16; 'received:webfaction.com': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'header:User-Agent:1': 0.23; 'byte': 0.24; "shouldn't": 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'header:In-Reply- To:1': 0.27; 'am,': 0.29; 'wonder': 0.29; 'converting': 0.30; 'that.': 0.31; 'work:': 0.31; 'url:python': 0.33; 'becomes': 0.33; 'subject:from': 0.34; 'but': 0.35; 'there': 0.35; 'i.e.': 0.36; 'sequence': 0.36; 'next': 0.36; 'url:org': 0.36; 'two': 0.37; 'url:library': 0.38; 'pm,': 0.38; 'how': 0.40; 'url:3': 0.61; 'become': 0.64; 'direct': 0.67; 'subject:get': 0.81; 'overlooked': 0.84; 'presumably': 0.84
Date Thu, 30 May 2013 15:22:26 -0400
From Ned Batchelder <ned@nedbatchelder.com>
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130509 Thunderbird/17.0.6
MIME-Version 1.0
To Mok-Kong Shen <mok-kong.shen@t-online.de>
Subject Re: How to get an integer from a sequence of bytes
References <knvrhf$n5n$1@news.albasani.net> <mailman.2253.1369668622.3114.python-list@python.org> <ko85jp$vn3$1@news.albasani.net>
In-Reply-To <ko85jp$vn3$1@news.albasani.net>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
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.2447.1369941788.3114.python-list@python.org> (permalink)
Lines 34
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1369941788 news.xs4all.nl 15880 [2001:888:2000:d::a6]:39424
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:46535

Show key headers only | View raw


On 5/30/2013 2:26 PM, Mok-Kong Shen wrote:
> Am 27.05.2013 17:30, schrieb Ned Batchelder:
>> On 5/27/2013 10:45 AM, Mok-Kong Shen wrote:
>>> From an int one can use to_bytes to get its individual bytes,
>>> but how can one reconstruct the int from the sequence of bytes?
>>>
>> The next thing in the docs after int.to_bytes is int.from_bytes:
>> http://docs.python.org/3.3/library/stdtypes.html#int.from_bytes
>
> I am sorry to have overlooked that. But one thing I yet wonder is why
> there is no direct possibilty of converting a byte to an int in [0,255],
> i.e. with a constrct int(b), where b is a byte.
>

Presumably you want this to work:

     >>> int(b'\x03')
     3

But you also want this to work:

     >>> int(b'7')
     7

These two interpretations are incompatible.  If b'\x03' becomes 3, then 
shouldn't b'\x37' become 55?  But b'\x37' is b'7', and you want that to 
be 7.

--Ned.

> M. K. Shen
>

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


Thread

How to get an integer from a sequence of bytes Mok-Kong Shen <mok-kong.shen@t-online.de> - 2013-05-27 16:45 +0200
  Re: How to get an integer from a sequence of bytes Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-27 15:00 +0000
    RE: How to get an integer from a sequence of bytes Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-28 03:37 +0300
  Re: How to get an integer from a sequence of bytes Ned Batchelder <ned@nedbatchelder.com> - 2013-05-27 11:30 -0400
    Re: How to get an integer from a sequence of bytes Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-28 00:31 +0000
      Re: How to get an integer from a sequence of bytes Dave Angel <davea@davea.name> - 2013-05-27 20:41 -0400
    Re: How to get an integer from a sequence of bytes Mok-Kong Shen <mok-kong.shen@t-online.de> - 2013-05-30 20:26 +0200
      Re: How to get an integer from a sequence of bytes Ian Kelly <ian.g.kelly@gmail.com> - 2013-05-30 12:42 -0600
        Re: How to get an integer from a sequence of bytes jmfauth <wxjmfauth@gmail.com> - 2013-05-30 11:53 -0700
      Re: How to get an integer from a sequence of bytes Ned Batchelder <ned@nedbatchelder.com> - 2013-05-30 15:22 -0400
        Re: How to get an integer from a sequence of bytes Mok-Kong Shen <mok-kong.shen@t-online.de> - 2013-06-02 21:25 +0200
          Re: How to get an integer from a sequence of bytes Chris Angelico <rosuav@gmail.com> - 2013-06-03 05:54 +1000
          Re: How to get an integer from a sequence of bytes Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-06-02 21:48 -0400
            Re: How to get an integer from a sequence of bytes Grant Edwards <invalid@invalid.invalid> - 2013-06-03 14:31 +0000
              Re: How to get an integer from a sequence of bytes Dave Angel <d@davea.name> - 2013-06-03 18:07 -0400
                Re: How to get an integer from a sequence of bytes Grant Edwards <invalid@invalid.invalid> - 2013-06-03 22:34 +0000
              Re: How to get an integer from a sequence of bytes Dan Stromberg <drsalists@gmail.com> - 2013-06-03 15:41 -0700
                Re: How to get an integer from a sequence of bytes Grant Edwards <invalid@invalid.invalid> - 2013-06-04 13:39 +0000
                Re: How to get an integer from a sequence of bytes Joshua Landau <joshua.landau.ws@gmail.com> - 2013-06-04 20:51 +0100
                Re: How to get an integer from a sequence of bytes Chris Angelico <rosuav@gmail.com> - 2013-06-05 07:49 +1000
                Re: How to get an integer from a sequence of bytes Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-06-04 20:34 -0400
                Re: How to get an integer from a sequence of bytes Tim Roberts <timr@probo.com> - 2013-06-04 22:11 -0700
                Re: How to get an integer from a sequence of bytes Fábio Santos <fabiosantosart@gmail.com> - 2013-06-12 15:00 +0100
                Re: How to get an integer from a sequence of bytes Grant Edwards <invalid@invalid.invalid> - 2013-06-12 14:42 +0000
              RE: How to get an integer from a sequence of bytes Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-06-04 02:18 +0300
                Re: How to get an integer from a sequence of bytes Grant Edwards <invalid@invalid.invalid> - 2013-06-04 13:42 +0000
                RE: How to get an integer from a sequence of bytes Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-06-04 16:58 +0300
              Re: How to get an integer from a sequence of bytes Dan Stromberg <drsalists@gmail.com> - 2013-06-03 16:47 -0700
  Re: How to get an integer from a sequence of bytes Grant Edwards <invalid@invalid.invalid> - 2013-05-28 16:04 +0000

csiph-web