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


Groups > comp.lang.python > #46528

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!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.111
X-Spam-Level *
X-Spam-Evidence '*H*': 0.78; '*S*': 0.00; 'bytes,': 0.09; 'subject:How': 0.10; '10:45': 0.16; 'length,': 0.16; 'range(0,': 0.16; 'wrote:': 0.18; 'thu,': 0.19; '>>>': 0.22; 'byte': 0.24; 'bytes': 0.24; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'wonder': 0.29; 'converting': 0.30; 'message-id:@mail.gmail.com': 0.30; 'that.': 0.31; 'url:python': 0.33; 'subject:from': 0.34; 'received:209.85': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'i.e.': 0.36; 'sequence': 0.36; 'next': 0.36; 'url:org': 0.36; 'received:209': 0.37; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'url:3': 0.61; '30,': 0.65; 'direct': 0.67; 'viewed': 0.74; 'subject:get': 0.81; 'overlooked': 0.84; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=8+nJr0TZRK32zoz4v/kqhBcaQ2WgM+mV84TE1FpamYU=; b=Q8syc7hhXvkE3/A49eoHgaUSJj/L/HTgIv7lK98ssATvLtUjkop6QC2SBt8L8IMKW3 xnsJB6BUjntoe7wxt35BrKDepSajzy4R8Bk/KKDnLeQmBUR8+VM7Y0uQGH/CXIfUCvj2 G2ofL7K/EgTtrmqdiv45kFZLHWMqxDxFxRvxybyssDmXGrKrISYouxhDx9ye8op3Eq1v W8kyr9Rl9YMS8U+v0VZYs0l9w7vHdzIMyWglrQOB5LnvL6fGzxvqDjuFJOLG+lx30F/W xpI9b/+INAy2yQ2xaox+dNR4iLw10YlQavZ10FBVtXq/MzWJrbZTfc5ekwSZNQra8ab7 Zw7w==
X-Received by 10.66.122.8 with SMTP id lo8mr9574225pab.165.1369939385057; Thu, 30 May 2013 11:43:05 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <ko85jp$vn3$1@news.albasani.net>
References <knvrhf$n5n$1@news.albasani.net> <mailman.2253.1369668622.3114.python-list@python.org> <ko85jp$vn3$1@news.albasani.net>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Thu, 30 May 2013 12:42:24 -0600
Subject Re: How to get an integer from a sequence of bytes
To Python <python-list@python.org>
Content-Type text/plain; charset=ISO-8859-1
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.2444.1369939393.3114.python-list@python.org> (permalink)
Lines 19
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1369939393 news.xs4all.nl 15948 [2001:888:2000:d::a6]:45247
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:46528

Show key headers only | View raw


On Thu, May 30, 2013 at 12:26 PM, Mok-Kong Shen
<mok-kong.shen@t-online.de> 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.

The bytes object can be viewed as a sequence of ints.  So if b is a
bytes object of non-zero length, then b[0] is an int in range(0, 256).

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