Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #46200 > unrolled thread
| Started by | Mok-Kong Shen <mok-kong.shen@t-online.de> |
|---|---|
| First post | 2013-05-27 16:45 +0200 |
| Last post | 2013-05-28 16:04 +0000 |
| Articles | 20 on this page of 29 — 15 participants |
Back to article view | Back to comp.lang.python
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 1 of 2 [1] 2 Next page →
| From | Mok-Kong Shen <mok-kong.shen@t-online.de> |
|---|---|
| Date | 2013-05-27 16:45 +0200 |
| Subject | How to get an integer from a sequence of bytes |
| Message-ID | <knvrhf$n5n$1@news.albasani.net> |
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? Thanks in advance. M. K. Shen
[toc] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2013-05-27 15:00 +0000 |
| Message-ID | <51a37516$0$30002$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #46200 |
On Mon, 27 May 2013 16:45:05 +0200, 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? Here's one way: py> n = 11999102937234 py> m = 0 py> for b in n.to_bytes(6, 'big'): ... m = 256*m + b ... py> m == n True -- Steven
[toc] | [prev] | [next] | [standalone]
| From | Carlos Nepomuceno <carlosnepomuceno@outlook.com> |
|---|---|
| Date | 2013-05-28 03:37 +0300 |
| Message-ID | <mailman.2270.1369701466.3114.python-list@python.org> |
| In reply to | #46202 |
---------------------------------------- > From: steve+comp.lang.python@pearwood.info > Subject: Re: How to get an integer from a sequence of bytes > Date: Mon, 27 May 2013 15:00:39 +0000 > To: python-list@python.org > > On Mon, 27 May 2013 16:45:05 +0200, 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? > > Here's one way: > > py> n = 11999102937234 > py> m = 0 > py> for b in n.to_bytes(6, 'big'): > ... m = 256*m + b > ... > py> m == n > True > > > -- > Steven > > -- > http://mail.python.org/mailman/listinfo/python-list Python 2 doesn't have to_bytes()! :( # Python 2, LSB 1st def to_lil_bytes(x): r = [] while x != 0: r.append(int(x & 0b11111111)) x>>= 8 return r # Python 2, LSB 1st def from_lil_bytes(l): x = 0 for i in range(len(l)-1, -1, -1): x <<= 8 x |= l[i] return x # Python 2, MSB 1st def to_big_bytes(x): r = [] while x != 0: r.insert(0, int(x & 0b11111111)) x>>= 8 return r # Python 2, MSB 1st def from_big_bytes(l): x = 0 for i in range(len(l)): x <<= 8 x |= l[i] return x Can it be faster?
[toc] | [prev] | [next] | [standalone]
| From | Ned Batchelder <ned@nedbatchelder.com> |
|---|---|
| Date | 2013-05-27 11:30 -0400 |
| Message-ID | <mailman.2253.1369668622.3114.python-list@python.org> |
| In reply to | #46200 |
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 --Ned. > Thanks in advance. > > M. K. Shen
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2013-05-28 00:31 +0000 |
| Message-ID | <51a3faca$0$29966$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #46204 |
On Mon, 27 May 2013 11:30:18 -0400, Ned Batchelder wrote: > 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: And I can't believe I missed that too :-( -- Steven
[toc] | [prev] | [next] | [standalone]
| From | Dave Angel <davea@davea.name> |
|---|---|
| Date | 2013-05-27 20:41 -0400 |
| Message-ID | <mailman.2271.1369701741.3114.python-list@python.org> |
| In reply to | #46236 |
On 05/27/2013 08:31 PM, Steven D'Aprano wrote: > On Mon, 27 May 2013 11:30:18 -0400, Ned Batchelder wrote: > >> 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: > > And I can't believe I missed that too :-( > > And that approach probably works for negative ints too. -- DaveA
[toc] | [prev] | [next] | [standalone]
| From | Mok-Kong Shen <mok-kong.shen@t-online.de> |
|---|---|
| Date | 2013-05-30 20:26 +0200 |
| Message-ID | <ko85jp$vn3$1@news.albasani.net> |
| In reply to | #46204 |
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. M. K. Shen
[toc] | [prev] | [next] | [standalone]
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2013-05-30 12:42 -0600 |
| Message-ID | <mailman.2444.1369939393.3114.python-list@python.org> |
| In reply to | #46525 |
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).
[toc] | [prev] | [next] | [standalone]
| From | jmfauth <wxjmfauth@gmail.com> |
|---|---|
| Date | 2013-05-30 11:53 -0700 |
| Message-ID | <e5ef97fb-1449-4e92-af16-08305648fc2d@l5g2000vbn.googlegroups.com> |
| In reply to | #46528 |
On 30 mai, 20:42, Ian Kelly <ian.g.ke...@gmail.com> wrote:
> On Thu, May 30, 2013 at 12:26 PM, Mok-Kong Shen
>
> <mok-kong.s...@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).
----
Well, Python now "speaks" only "integer", the rest is
commodity and there is a good coherency.
>>> bin(255)
'0b11111111'
>>> oct(255)
'0o377'
>>> 255
255
>>> hex(255)
'0xff'
>>>
>>> int('0b11111111', 2)
255
>>> int('0o377', 8)
255
>>> int('255')
255
>>> int('0xff', 16)
255
>>>
>>> 0b11111111
255
>>> 0o377
255
>>> 255
255
>>> 0xff
255
>>>
>>> type(0b11111111)
<class 'int'>
>>> type(0o377)
<class 'int'>
>>> type(255)
<class 'int'>
>>> type(0xff)
<class 'int'>
jmf
[toc] | [prev] | [next] | [standalone]
| From | Ned Batchelder <ned@nedbatchelder.com> |
|---|---|
| Date | 2013-05-30 15:22 -0400 |
| Message-ID | <mailman.2447.1369941788.3114.python-list@python.org> |
| In reply to | #46525 |
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
>
[toc] | [prev] | [next] | [standalone]
| From | Mok-Kong Shen <mok-kong.shen@t-online.de> |
|---|---|
| Date | 2013-06-02 21:25 +0200 |
| Message-ID | <kog67o$pt2$1@news.albasani.net> |
| In reply to | #46535 |
Am 30.05.2013 21:22, schrieb Ned Batchelder: > > 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. 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. M. K. Shen
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-06-03 05:54 +1000 |
| Message-ID | <mailman.2560.1370202861.3114.python-list@python.org> |
| In reply to | #46726 |
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
[toc] | [prev] | [next] | [standalone]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2013-06-02 21:48 -0400 |
| Message-ID | <mailman.2571.1370224134.3114.python-list@python.org> |
| In reply to | #46726 |
On Sun, 02 Jun 2013 21:25:45 +0200, Mok-Kong Shen
<mok-kong.shen@t-online.de> declaimed the following in
gmane.comp.python.general:
> 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
In other languages "byte" is an 8-bit signed/unsigned numeric.
But what you have is a Python 3.x "bytes" structure -- similar to a
character string in Python 2.x...
> 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.
>
As you've been shown, the first step is that you may have to
subscript it; even with just one byte, the structure is still a
"string/array". NOTE: that example doesn't work in 2.7, since
subscripting what is a "string" still returns a substring (of one
character).
Python doesn't have a "numeric" byte type -- the b"..." is an
"array" of 8-bit values in Python 3.x, and is just a character string in
2.x
A language like C didn't have a "string" type... "char" was a
pseudonym for "numeric byte" (and some even support "unsigned char" vs
"signed char").
Maybe you'd like to program in Ada... Where "7" is a "string of
length 1" and '7' is a character -- and you have to do type conversions
to assign the latter to the former.
Heck:
with Text_IO; use Text_IO;
procedure Bytes is
begin
if "7" = '7' then
Put_Line ("string 7 is equal to character 7");
else
Put_Line ("string 7 is NOT equal to character 7");
end if;
end Bytes;
WON'T compile... string can not be compared to character!
with Text_IO; use Text_IO;
procedure Bytes is
A_String : String (1 .. 1);
A_Char : Character := '7';
begin
A_String := A_Char;
end Bytes;
The above fails to compile, whereas the following is valid Ada
with Text_IO; use Text_IO;
procedure Bytes is
A_String : String (1 .. 1);
A_Char : Character := '7';
begin
A_String(1) := A_Char;
end Bytes;
Don't even ask about /numeric/ bytes and strings (or characters). Or
lets...
with Text_IO; use Text_IO;
procedure Bytes is
type Byte is mod 256;
A_String : String (1 .. 1);
Char : Byte := 7;
begin
A_String (1) := Char;
end Bytes;
Fails... But...
with Text_IO; use Text_IO;
procedure Bytes is
type Byte is mod 256;
A_String : String (1 .. 1);
Char : Byte := 7;
begin
A_String (1) := Character'Val (Char);
end Bytes;
That takes a byte data type (unsigned 8-bit value)... Asks for the
CHARACTER data type having the value equivalent to the "position" of the
byte... And then stuff that into the only element of a STRING data type.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [next] | [standalone]
| From | Grant Edwards <invalid@invalid.invalid> |
|---|---|
| Date | 2013-06-03 14:31 +0000 |
| Message-ID | <koi9ch$3ps$1@reader1.panix.com> |
| In reply to | #46746 |
On 2013-06-03, Dennis Lee Bieber <wlfraed@ix.netcom.com> wrote:
> On Sun, 02 Jun 2013 21:25:45 +0200, Mok-Kong Shen
><mok-kong.shen@t-online.de> declaimed the following in
> gmane.comp.python.general:
>
>
>> 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
>
> In other languages "byte" is an 8-bit signed/unsigned numeric.
That's a common assumption, but historically, a "byte" was merely the
smallest addressable unit of memory. The size of a "byte" on widely
used used CPUs ranged from 4 bits to 60 bits.
Quoting from http://en.wikipedia.org/wiki/Byte
"The size of the byte has historically been hardware
dependent and no definitive standards existed that mandated the
size."
That's why IEEE standards always use the word "octet" when referring a
value containing 8 bits.
Only recently has it become common to assume that an "byte" contains 8
bits.
--
Grant Edwards grant.b.edwards Yow! It's a lot of fun
at being alive ... I wonder if
gmail.com my bed is made?!?
[toc] | [prev] | [next] | [standalone]
| From | Dave Angel <d@davea.name> |
|---|---|
| Date | 2013-06-03 18:07 -0400 |
| Message-ID | <mailman.2607.1370297269.3114.python-list@python.org> |
| In reply to | #46792 |
On 06/03/2013 10:31 AM, Grant Edwards wrote: > On 2013-06-03, Dennis Lee Bieber <wlfraed@ix.netcom.com> wrote: >> On Sun, 02 Jun 2013 21:25:45 +0200, Mok-Kong Shen >> <mok-kong.shen@t-online.de> declaimed the following in >> gmane.comp.python.general: >> >> >>> 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 >> >> In other languages "byte" is an 8-bit signed/unsigned numeric. > > That's a common assumption, but historically, a "byte" was merely the > smallest addressable unit of memory. The size of a "byte" on widely > used used CPUs ranged from 4 bits to 60 bits. > <Hehe> I recall rewriting the unpacking algorithm to get the 10 characters from each byte, on such a machine. -- DaveA
[toc] | [prev] | [next] | [standalone]
| From | Grant Edwards <invalid@invalid.invalid> |
|---|---|
| Date | 2013-06-03 22:34 +0000 |
| Message-ID | <koj5ks$sb2$1@reader1.panix.com> |
| In reply to | #46810 |
On 2013-06-03, Dave Angel <d@davea.name> wrote:
> On 06/03/2013 10:31 AM, Grant Edwards wrote:
>> On 2013-06-03, Dennis Lee Bieber <wlfraed@ix.netcom.com> wrote:
>>> On Sun, 02 Jun 2013 21:25:45 +0200, Mok-Kong Shen
>>> <mok-kong.shen@t-online.de> declaimed the following in
>>> gmane.comp.python.general:
>>>
>>>
>>>> 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
>>>
>>> In other languages "byte" is an 8-bit signed/unsigned numeric.
>>
>> That's a common assumption, but historically, a "byte" was merely the
>> smallest addressable unit of memory. The size of a "byte" on widely
>> used used CPUs ranged from 4 bits to 60 bits.
>>
>
><Hehe> I recall rewriting the unpacking algorithm to get the 10
> characters from each byte, on such a machine.
Yep. IIRC there were CDC machines (Cyber 6600?) with a 60-bit wide
"byte" and a 6-bit wide upper-case-only character set. ISTM that the
Pascal compiler limited you to 6 significant characters in variable
names so that it could use a simple single register compare while
doing symbol lookups...
I think some IBM machines had 60-bit "bytes" as well.
--
Grant Edwards grant.b.edwards Yow! DIDI ... is that a
at MARTIAN name, or, are we
gmail.com in ISRAEL?
[toc] | [prev] | [next] | [standalone]
| From | Dan Stromberg <drsalists@gmail.com> |
|---|---|
| Date | 2013-06-03 15:41 -0700 |
| Message-ID | <mailman.2611.1370299311.3114.python-list@python.org> |
| In reply to | #46792 |
[Multipart message — attachments visible in raw view] — view raw
On Mon, Jun 3, 2013 at 7:31 AM, Grant Edwards <invalid@invalid.invalid>wrote: > That's a common assumption, but historically, a "byte" was merely the > smallest addressable unit of memory. The size of a "byte" on widely > used used CPUs ranged from 4 bits to 60 bits. > > Quoting from http://en.wikipedia.org/wiki/Byte > > "The size of the byte has historically been hardware > dependent and no definitive standards existed that mandated the > size." > > That's why IEEE standards always use the word "octet" when referring a > value containing 8 bits. > 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. 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.
[toc] | [prev] | [next] | [standalone]
| From | Grant Edwards <invalid@invalid.invalid> |
|---|---|
| Date | 2013-06-04 13:39 +0000 |
| Message-ID | <kokqma$574$1@reader1.panix.com> |
| In reply to | #46816 |
On 2013-06-03, Dan Stromberg <drsalists@gmail.com> wrote:
> On Mon, Jun 3, 2013 at 7:31 AM, Grant Edwards <invalid@invalid.invalid>wrote:
>
>> That's a common assumption, but historically, a "byte" was merely the
>> smallest addressable unit of memory. The size of a "byte" on widely
>> used used CPUs ranged from 4 bits to 60 bits.
>>
>> Quoting from http://en.wikipedia.org/wiki/Byte
>>
>> "The size of the byte has historically been hardware
>> dependent and no definitive standards existed that mandated the
>> size."
>>
>> That's why IEEE standards always use the word "octet" when referring a
>> value containing 8 bits.
>
> 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.
> Today though, it would be difficult to sell a conventional (Von Neumann)
> computer that didn't have 8 bit bytes.
There are tons (as in millions of units per month) of CPUs still being
sold in the DSP market with 16, 20, 24, and 32 bit "bytes". (When
writing C on a TMS320Cxx CPU sizeof (char) == sizeof (int) == sizeof
(long) == sizeof (float) == sizeof (double) == 1. They all contain 32
bits.
> Quantum computers would still sell if they were odd this way -
> they're going to be really different anyway.
--
Grant Edwards grant.b.edwards Yow! Either CONFESS now or
at we go to "PEOPLE'S COURT"!!
gmail.com
[toc] | [prev] | [next] | [standalone]
| From | Joshua Landau <joshua.landau.ws@gmail.com> |
|---|---|
| Date | 2013-06-04 20:51 +0100 |
| Message-ID | <mailman.2678.1370375539.3114.python-list@python.org> |
| In reply to | #46900 |
On 4 June 2013 14:39, Grant Edwards <invalid@invalid.invalid> wrote: > On 2013-06-03, Dan Stromberg <drsalists@gmail.com> wrote: >> Today though, it would be difficult to sell a conventional (Von Neumann) >> computer that didn't have 8 bit bytes. > > There are tons (as in millions of units per month) of CPUs still being > sold in the DSP market with 16, 20, 24, and 32 bit "bytes". (When > writing C on a TMS320Cxx CPU sizeof (char) == sizeof (int) == sizeof > (long) == sizeof (float) == sizeof (double) == 1. They all contain 32 > bits. ) *) for the bracket not in the reply Sorry.
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-06-05 07:49 +1000 |
| Message-ID | <mailman.2686.1370382598.3114.python-list@python.org> |
| In reply to | #46900 |
On Wed, Jun 5, 2013 at 5:51 AM, Joshua Landau <joshua.landau.ws@gmail.com> wrote: > On 4 June 2013 14:39, Grant Edwards <invalid@invalid.invalid> wrote: >> On 2013-06-03, Dan Stromberg <drsalists@gmail.com> wrote: >>> Today though, it would be difficult to sell a conventional (Von Neumann) >>> computer that didn't have 8 bit bytes. >> >> There are tons (as in millions of units per month) of CPUs still being >> sold in the DSP market with 16, 20, 24, and 32 bit "bytes". (When >> writing C on a TMS320Cxx CPU sizeof (char) == sizeof (int) == sizeof >> (long) == sizeof (float) == sizeof (double) == 1. They all contain 32 >> bits. > ) > > *) for the bracket not in the reply > > Sorry. So... can we cite http://xkcd.com/859/ in two threads at once, or does that create twice as much tension? Once an XKCD is un-cited, will it be garbage collected promptly, or do they contain refloops? ChrisA
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.lang.python
csiph-web