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: 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: References: From: Ian Kelly Date: Thu, 30 May 2013 12:42:24 -0600 Subject: Re: How to get an integer from a sequence of bytes To: Python 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Thu, May 30, 2013 at 12: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. 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).