Hello,
I need to convert the string "FFFFFFFF" to a long. To convert this
string I tried the following: 0xffffffff
-1 0xffffffffL
4294967295L
OK, this is what I want, so I tried
s = long("0xffffffffL")
ValueError: invalid literal for long(): 0xffffffffL
s = long("0xffffffff")
ValueError: invalid literal for long(): 0xffffffffL
What can I do?
Thank you in advance.
Stefan 16 3709
On Fri, 2005-11-18 at 11:04, on******@gmail.com wrote: Hello,
I need to convert the string "FFFFFFFF" to a long. To convert this string I tried the following: 0xffffffff -1 0xffffffffL 4294967295L
OK, this is what I want, so I tried
s = long("0xffffffffL") ValueError: invalid literal for long(): 0xffffffffL
s = long("0xffffffff") ValueError: invalid literal for long(): 0xffffffffL
What can I do?
Thank you in advance. Stefan
Leave out the "0x" prefix and tell long() that you're using base 16: long("ffffffff", 16)
4294967295L
HTH,
Carsten.
On Fri, 2005-11-18 at 11:04, on******@gmail.com wrote: Hello,
I need to convert the string "FFFFFFFF" to a long. To convert this string I tried the following: 0xffffffff -1 0xffffffffL 4294967295L
OK, this is what I want, so I tried
s = long("0xffffffffL") ValueError: invalid literal for long(): 0xffffffffL
s = long("0xffffffff") ValueError: invalid literal for long(): 0xffffffffL
What can I do?
Thank you in advance. Stefan
Leave out the "0x" prefix and tell long() that you're using base 16: long("ffffffff", 16)
4294967295L
HTH,
Carsten.
Carsten Haese wrote: OK, this is what I want, so I tried
s = long("0xffffffffL") ValueError: invalid literal for long(): 0xffffffffL
s = long("0xffffffff") ValueError: invalid literal for long(): 0xffffffffL
What can I do?
Thank you in advance. Stefan
Leave out the "0x" prefix and tell long() that you're using base 16:
long("ffffffff", 16) 4294967295L
It's sufficient to tell long() that you're using base 16:
#v+ long('0xffffL', 16)
65535L
#v-
Cheers,
--
Klaus Alexander Seistrup
Copenhagen, Denmark http://seistrup.dk/
Carsten Haese wrote: OK, this is what I want, so I tried
s = long("0xffffffffL") ValueError: invalid literal for long(): 0xffffffffL
s = long("0xffffffff") ValueError: invalid literal for long(): 0xffffffffL
What can I do?
Thank you in advance. Stefan
Leave out the "0x" prefix and tell long() that you're using base 16:
long("ffffffff", 16) 4294967295L
It's sufficient to tell long() that you're using base 16:
#v+ long('0xffffL', 16)
65535L
#v-
Cheers,
--
Klaus Alexander Seistrup
Copenhagen, Denmark http://seistrup.dk/ on******@gmail.com wrote: 0xffffffffL 4294967295L
OK, this is what I want, so I tried
s = long("0xffffffffL") ValueError: invalid literal for long(): 0xffffffffL int("0xffffffff", 0)
4294967295L
STeVe on******@gmail.com wrote: 0xffffffffL 4294967295L
OK, this is what I want, so I tried
s = long("0xffffffffL") ValueError: invalid literal for long(): 0xffffffffL int("0xffffffff", 0)
4294967295L
STeVe
Steven Bethard <st************@gmail.com> wrote: on******@gmail.com wrote: s = long("0xffffffffL") ValueError: invalid literal for long(): 0xffffffffL int("0xffffffff", 0) 4294967295L
So why does the base argument to int() (or long()) default to
10 and not 0?
--
\S -- si***@chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
___ | "Frankly I have no feelings towards penguins one way or the other"
\X/ | -- Arthur C. Clarke
her nu becomež se bera eadward ofdun hlęddre heafdes bęce bump bump bump
Steven Bethard <st************@gmail.com> wrote: on******@gmail.com wrote: s = long("0xffffffffL") ValueError: invalid literal for long(): 0xffffffffL int("0xffffffff", 0) 4294967295L
So why does the base argument to int() (or long()) default to
10 and not 0?
--
\S -- si***@chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
___ | "Frankly I have no feelings towards penguins one way or the other"
\X/ | -- Arthur C. Clarke
her nu becomež se bera eadward ofdun hlęddre heafdes bęce bump bump bump
Sion Arrowsmith wrote: Steven Bethard <st************@gmail.com> wrote:
on******@gmail.com wrote:
s = long("0xffffffffL") ValueError: invalid literal for long(): 0xffffffffL
>int("0xffffffff", 0)
4294967295L
So why does the base argument to int() (or long()) default to 10 and not 0?
Because it's designed for numbers normal people provide, not for numbers
programmers provide. Normal people see 0123 as being equal to 123, not 83.
Sion Arrowsmith wrote: Steven Bethard <st************@gmail.com> wrote:
on******@gmail.com wrote:
s = long("0xffffffffL") ValueError: invalid literal for long(): 0xffffffffL
>int("0xffffffff", 0)
4294967295L
So why does the base argument to int() (or long()) default to 10 and not 0?
Because it's designed for numbers normal people provide, not for numbers
programmers provide. Normal people see 0123 as being equal to 123, not 83.
On Fri, 18 Nov 2005 11:10:06 -0500, Carsten Haese wrote: s = long("0xffffffffL") ValueError: invalid literal for long(): 0xffffffffL
s = long("0xffffffff") ValueError: invalid literal for long(): 0xffffffffL
What can I do?
Thank you in advance. Stefan
Leave out the "0x" prefix and tell long() that you're using base 16:
long("ffffffff", 16)
4294967295L
Or leave the prefix in, and tell Python to use the prefix to predict the
base:
py> long("0xffffffffL", 0)
4294967295L
--
Steven.
On Fri, 18 Nov 2005 11:10:06 -0500, Carsten Haese wrote: s = long("0xffffffffL") ValueError: invalid literal for long(): 0xffffffffL
s = long("0xffffffff") ValueError: invalid literal for long(): 0xffffffffL
What can I do?
Thank you in advance. Stefan
Leave out the "0x" prefix and tell long() that you're using base 16:
long("ffffffff", 16)
4294967295L
Or leave the prefix in, and tell Python to use the prefix to predict the
base:
py> long("0xffffffffL", 0)
4294967295L
--
Steven.
On Fri, 18 Nov 2005 17:49:50 +0000, Leif K-Brooks wrote: Sion Arrowsmith wrote: Steven Bethard <st************@gmail.com> wrote:
on******@gmail.com wrote:
s = long("0xffffffffL") ValueError: invalid literal for long(): 0xffffffffL
>>int("0xffffffff", 0)
4294967295L
So why does the base argument to int() (or long()) default to 10 and not 0?
Because it's designed for numbers normal people provide, not for numbers programmers provide. Normal people see 0123 as being equal to 123, not 83.
The base arguments to int() and long() default to base 10 because base 10
is used by just about all people and cultures in the world. Leading zeroes
are mathematically meaningless: 0123 means 0*base**3 + 1*base**2 +
2*base**1 + 3*base**0, which is identical to 123 no matter what base you
choose.
Interpreting 0123 in octal is a sop to programmers who want/need
compatibility to the C bug that changes the meaning of numeric literals
according to the presence or absence of a leading zero. Alas I suspect
that this particular piece of illogic is too ingrained now to ever
eradicate.
--
Steven.
On Fri, 18 Nov 2005 17:49:50 +0000, Leif K-Brooks wrote: Sion Arrowsmith wrote: Steven Bethard <st************@gmail.com> wrote:
on******@gmail.com wrote:
s = long("0xffffffffL") ValueError: invalid literal for long(): 0xffffffffL
>>int("0xffffffff", 0)
4294967295L
So why does the base argument to int() (or long()) default to 10 and not 0?
Because it's designed for numbers normal people provide, not for numbers programmers provide. Normal people see 0123 as being equal to 123, not 83.
The base arguments to int() and long() default to base 10 because base 10
is used by just about all people and cultures in the world. Leading zeroes
are mathematically meaningless: 0123 means 0*base**3 + 1*base**2 +
2*base**1 + 3*base**0, which is identical to 123 no matter what base you
choose.
Interpreting 0123 in octal is a sop to programmers who want/need
compatibility to the C bug that changes the meaning of numeric literals
according to the presence or absence of a leading zero. Alas I suspect
that this particular piece of illogic is too ingrained now to ever
eradicate.
--
Steven.
Thank you, for all the good answers. Somehow I overlooked the 'radix'
option in the docs.
S
Thank you, for all the good answers. Somehow I overlooked the 'radix'
option in the docs.
S This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Joe Peterson |
last post by:
I could not find another example of this via internet searches, so here
it is... I am wondering if this is a python bug or otherwise. The
first example of this happened in a larger program of...
|
by: Num |
last post by:
Hi all,
I have to convert a J2EE date as a long ("Millis") in a .NET date as a
long ("Ticks")
In Java, currentTimeMillis, is the difference, measured in
milliseconds, between the current time...
|
by: Adam Ierymenko |
last post by:
I have a question that might have been asked before, but I have not been
able to find anything via groups.google.com or any web search that is
definative.
I am writing an evolutionary AI...
|
by: Jerry |
last post by:
I have an off-the-shelf app that uses an Access database as its
backend. One of the tables contains a field with an "OLE Object"
datatype. I'm writing some reports against this database, and I...
|
by: ondekoza |
last post by:
Hello,
I need to convert the string "FFFFFFFF" to a long. To convert this
string I tried the following:
>>> 0xffffffff
-1
>>> 0xffffffffL
4294967295L
OK, this is what I want, so I tried
|
by: Zero |
last post by:
Hi everybody,
i want to write a small program, which shows me the biggest and
smallest number in dependance of the data type.
For int the command could be:
...
|
by: RON |
last post by:
I have to read a long text field (it's a PDF) from SQL Server in a VB.NET
(2003) app. Here's the code I have:
Sub GetPDF(byval Path as string)
'objConnection created elsewhere; not the problem...
|
by: RON |
last post by:
have to read a long text field (it's a PDF stored in a column) from SQL
Server in a VB.NET (2003) app. Here's the code I have:
Sub GetPDF(byval Path as string)
'objConnection created elsewhere;...
|
by: Curious |
last post by:
Hi,
I have two columns defined as DateTime type in the Visual Designer,
i.e., Dataset.xsd.
In the grid to which the columns are bound, they're both displayed as
date, for instance, 5/23/2007....
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
| |