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


Groups > comp.lang.python > #46200 > unrolled thread

How to get an integer from a sequence of bytes

Started byMok-Kong Shen <mok-kong.shen@t-online.de>
First post2013-05-27 16:45 +0200
Last post2013-05-28 16:04 +0000
Articles 9 on this page of 29 — 15 participants

Back to article view | Back to comp.lang.python


Contents

  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

Page 2 of 2 — ← Prev page 1 [2]


#46986

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2013-06-04 20:34 -0400
Message-ID<mailman.2694.1370392497.3114.python-list@python.org>
In reply to#46900
On Tue, 4 Jun 2013 13:39:22 +0000 (UTC), Grant Edwards
<invalid@invalid.invalid> declaimed the following in
gmane.comp.python.general:

> 
> But you couldn't address individual 6-bit "hextets" in memory could
> you?  My recollection is that incrementing a memory address got you
> the next 60-bit chunk -- that means that by the older terminology a
> "byte" was 60 bits.  A "character" was 6 bits, and a single register
> or memory location could hold 6 characters.
>

	How would you interpret the Xerox Sigma instruction set then...

	It had LW (load word), LH (load halfword), LB (load byte)
instructions... BUT the address argument was always considered as a
32-bit word (word 1 was 32-bits after word 0).

	To actually read a sequence of bytes required using LB with an
auxiliary index register, which identified which byte in the word was
desired.
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
        wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [prev] | [next] | [standalone]


#47015

FromTim Roberts <timr@probo.com>
Date2013-06-04 22:11 -0700
Message-ID<mrhtq8toairg1q66npg235jnukkqjlqf79@4ax.com>
In reply to#46900
Grant Edwards <invalid@invalid.invalid> wrote:

>On 2013-06-03, Dan Stromberg <drsalists@gmail.com> wrote:
>>
>> When I was a Freshman in college, I used a CDC Cyber a lot; it had 6 bit
>> bytes and 60 bit words.  This was in 1985.
>
>But you couldn't address individual 6-bit "hextets" in memory could
>you?  My recollection is that incrementing a memory address got you
>the next 60-bit chunk -- that means that by the older terminology a
>"byte" was 60 bits.  A "character" was 6 bits, and a single register
>or memory location could hold 6 characters.

A single machine word was 60 bits, so a single register read got you 10
characters.  There were three sets of registers -- the X registers were 60
bits, the A and B registers were 18 bits, which was the size of the largest
possible address.

CDC didn't actually use the term "byte".  That was IBM's domain.

When ASCII became unavoidable, most programs changed to using 5x 12-bit
"bytes" per word.

Ah, memories.  I spent 10 years working for Control Data.
-- 
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

[toc] | [prev] | [next] | [standalone]


#47804

FromFábio Santos <fabiosantosart@gmail.com>
Date2013-06-12 15:00 +0100
Message-ID<mailman.3108.1371045660.3114.python-list@python.org>
In reply to#47015

[Multipart message — attachments visible in raw view] — view raw

On 5 Jun 2013 06:23, "Tim Roberts" <timr@probo.com> wrote:
> A single machine word was 60 bits, so a single register read got you 10
> characters.

10 characters! Now that sounds like it's enough to actually store a word.
However long words can inadverten be cropped.

[toc] | [prev] | [next] | [standalone]


#47808

FromGrant Edwards <invalid@invalid.invalid>
Date2013-06-12 14:42 +0000
Message-ID<kpa1ch$qhk$2@reader1.panix.com>
In reply to#47804
On 2013-06-12, F?bio Santos <fabiosantosart@gmail.com> wrote:
> On 5 Jun 2013 06:23, "Tim Roberts" <timr@probo.com> wrote:
>> A single machine word was 60 bits, so a single register read got you 10
>> characters.
>
> 10 characters! Now that sounds like it's enough to actually store a word.
> However long words can inadverten be cropped.

Only the first 10 characters in variable names were significant when
you wrote Pascal programs (I don't remember if that was true for
FORTRAN, but I bet it was).

-- 
Grant Edwards               grant.b.edwards        Yow! I'm gliding over a
                                  at               NUCLEAR WASTE DUMP near
                              gmail.com            ATLANTA, Georgia!!

[toc] | [prev] | [next] | [standalone]


#46821

FromCarlos Nepomuceno <carlosnepomuceno@outlook.com>
Date2013-06-04 02:18 +0300
Message-ID<mailman.2614.1370301602.3114.python-list@python.org>
In reply to#46792
________________________________
> Date: Mon, 3 Jun 2013 15:41:41 -0700 
> Subject: Re: How to get an integer from a sequence of bytes 
> From: drsalists@gmail.com 
> To: python-list@python.org 
[...]
> Today though, it would be difficult to sell a conventional (Von  
> Neumann) computer that didn't have 8 bit bytes.  Quantum computers  
> would still sell if they were odd this way - they're going to be really  
> different anyway. 

Nowadays it would be a hard task to find a Von Neumann architecture machine.

Most of current CPUs are variants of the Harvard architecture: they separate instructions from data at the cache level. 		 	   		  

[toc] | [prev] | [next] | [standalone]


#46902

FromGrant Edwards <invalid@invalid.invalid>
Date2013-06-04 13:42 +0000
Message-ID<kokqsm$574$2@reader1.panix.com>
In reply to#46821
On 2013-06-03, Carlos Nepomuceno <carlosnepomuceno@outlook.com> wrote:
> ________________________________
>> Date: Mon, 3 Jun 2013 15:41:41 -0700 
>> Subject: Re: How to get an integer from a sequence of bytes 
>> From: drsalists@gmail.com 
>> To: python-list@python.org 
> [...]
>> Today though, it would be difficult to sell a conventional (Von  
>> Neumann) computer that didn't have 8 bit bytes.  Quantum computers  
>> would still sell if they were odd this way - they're going to be really  
>> different anyway. 
>
> Nowadays it would be a hard task to find a Von Neumann architecture
> machine.
>
> Most of current CPUs are variants of the Harvard architecture: they
> separate instructions from data at the cache level.  

VN designs are still very common in smaller CPUs (embedded stuff).

Even modern desktop CPUs are "logically" still Von Neumann designs
from the programmer's point of view (there's only a single address
space for both data and instructions).  The fact that there are two
sparate caches is almost entirely hidden from the user.  If you start
to do stuff like write self-modifying code, then _may_ start having to
worry about cache coherency.

-- 
Grant Edwards               grant.b.edwards        Yow! I request a weekend in
                                  at               Havana with Phil Silvers!
                              gmail.com            

[toc] | [prev] | [next] | [standalone]


#46905

FromCarlos Nepomuceno <carlosnepomuceno@outlook.com>
Date2013-06-04 16:58 +0300
Message-ID<mailman.2648.1370354353.3114.python-list@python.org>
In reply to#46902

[Multipart message — attachments visible in raw view] — view raw

> From: invalid@invalid.invalid
> Subject: Re: How to get an integer from a sequence of bytes
> Date: Tue, 4 Jun 2013 13:42:46 +0000
> To: python-list@python.org
[...]
> VN designs are still very common in smaller CPUs (embedded stuff).

DSPs perhaps... not CPUs. Even ARMs are Harvard variants.

> Even modern desktop CPUs are "logically" still Von Neumann designs
> from the programmer's point of view (there's only a single address
> space for both data and instructions).  The fact that there are two
> sparate caches is almost entirely hidden from the user.  If you start
> to do stuff like write self-modifying code, then _may_ start having to
> worry about cache coherency.

Code/data separation isn't the only aspect. VN architecture is totally serial, even for RAM.

It's been a while since we've got into the multi-core, multipath world. Even in embedded devices.

> -- 
> Grant Edwards               grant.b.edwards        Yow! I request a weekend in
>                                   at               Havana with Phil Silvers!
>                               gmail.com            
> -- 
> http://mail.python.org/mailman/listinfo/python-list
 		 	   		  

[toc] | [prev] | [next] | [standalone]


#46825

FromDan Stromberg <drsalists@gmail.com>
Date2013-06-03 16:47 -0700
Message-ID<mailman.2618.1370303255.3114.python-list@python.org>
In reply to#46792

[Multipart message — attachments visible in raw view] — view raw

On Mon, Jun 3, 2013 at 4:18 PM, Carlos Nepomuceno <
carlosnepomuceno@outlook.com> wrote:

> ________________________________
> > Date: Mon, 3 Jun 2013 15:41:41 -0700
> > Subject: Re: How to get an integer from a sequence of bytes
> > From: drsalists@gmail.com
> > To: python-list@python.org
> [...]
> > Today though, it would be difficult to sell a conventional (Von
> > Neumann) computer that didn't have 8 bit bytes.  Quantum computers
> > would still sell if they were odd this way - they're going to be really
> > different anyway.
>
> Nowadays it would be a hard task to find a Von Neumann architecture
> machine.
>
> Most of current CPUs are variants of the Harvard architecture: they
> separate instructions from data at the cache level.
>

I stand corrected.  Thank you.

[toc] | [prev] | [next] | [standalone]


#46305

FromGrant Edwards <invalid@invalid.invalid>
Date2013-05-28 16:04 +0000
Message-ID<ko2khh$9oh$5@reader1.panix.com>
In reply to#46200
On 2013-05-27, Mok-Kong Shen <mok-kong.shen@t-online.de> 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?

One way is using the struct module.

-- 
Grant Edwards               grant.b.edwards        Yow! Uh-oh!!  I forgot
                                  at               to submit to COMPULSORY
                              gmail.com            URINALYSIS!

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.python


csiph-web