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


Groups > comp.lang.python > #46730

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!news2.arglkargh.de!news.mixmin.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.019
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'subject:How': 0.10; 'python': 0.11; 'assigns': 0.16; 'byte,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'hexadecimal': 0.16; 'notation': 0.16; 'notation,': 0.16; 'wrote:': 0.18; 'code.': 0.18; '>>>': 0.22; 'code,': 0.22; 'byte': 0.24; 'mon,': 0.24; 'certain': 0.27; 'gets': 0.27; 'header:In- Reply-To:1': 0.27; 'point': 0.28; 'am,': 0.29; 'character': 0.29; 'message-id:@mail.gmail.com': 0.30; 'decimal': 0.31; 'ok.': 0.31; 'subject:from': 0.34; 'received:209.85': 0.35; 'received:209.85.220': 0.35; 'received:google.com': 0.35; 'received:209': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'different': 0.65; 'direct': 0.67; 'subject:get': 0.81; '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:date:message-id:subject:from:to :content-type; bh=R3IVji0DWPG2g1iK8mZ4hBb4VfkMaxRyox7g0BROZ/c=; b=Y4YArs1Wg1X3Tp8mIT+WCqwsCyIMnRFOjbyGa/5P7tMzL7y7UI24IstUc5JO3sqrCE sqAxjxwCPTU3fkSRa7xRNsKc0QdXbJC24caDCttUR2amiCMlDo4nQFcLPhTIGk/2226Q k8cNV6K861cMeBkoXrZ4AHQiA7yGKzGeQXB2FEkpi1oIe4pnBzH+U7aW5f1GlUVpKJKS DVrz/UwONbhD5bZt6ipHS6z7XEmPY3VwcWO33e46APg2TdIVZWiNN8D13Etfe3be56fv chk6+jj0b+NaxeMy+FI4hVbL1cXDLz/J5lQFG7hVDBfGlQSJZYJfmQ3uRVghkYZZ3mAk o5qA==
MIME-Version 1.0
X-Received by 10.52.155.67 with SMTP id vu3mr13469962vdb.94.1370202852048; Sun, 02 Jun 2013 12:54:12 -0700 (PDT)
In-Reply-To <kog67o$pt2$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> <mailman.2447.1369941788.3114.python-list@python.org> <kog67o$pt2$1@news.albasani.net>
Date Mon, 3 Jun 2013 05:54:11 +1000
Subject Re: How to get an integer from a sequence of bytes
From Chris Angelico <rosuav@gmail.com>
To 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.2560.1370202861.3114.python-list@python.org> (permalink)
Lines 15
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1370202861 news.xs4all.nl 15890 [2001:888:2000:d::a6]:58878
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:46730

Show key headers only | View raw


On Mon, Jun 3, 2013 at 5:25 AM, Mok-Kong Shen <mok-kong.shen@t-online.de> wrote:
> b'7' is the byte with the character 7 in a certain code, so that's
> ok. In other PLs one assigns an int to a byte, with that int in either
> decimal notation or hexadecimal notation, or else one assigns a
> character to it, in which case it gets the value of the character
> in a certain code. What I don't yet understand is why Python is
> apprently different from other PLs in that point in not allowing direct
> coersion of a byte to an int.

It does. Just subscript it:

>>> b'7'[0]
55

ChrisA

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