Re: Binary Decimals in Python

2010-03-30 Thread Mensanator
On Mar 30, 1:52 pm, MRAB wrote: > John Nagle wrote: > > aditya wrote: > >> On Mar 30, 10:49 am, Raymond Hettinger wrote: > >>> On Mar 30, 8:13 am, aditya wrote: > > To get the decimal representation of a binary number, I can just do > this: > int('11',2) # returns 3 > But dec

Re: Binary Decimals in Python

2010-03-30 Thread Chris Kaynor
Chris On Tue, Mar 30, 2010 at 11:14 AM, John Nagle wrote: > aditya wrote: > >> On Mar 30, 10:49 am, Raymond Hettinger wrote: >> >>> On Mar 30, 8:13 am, aditya wrote: >>> >>> To get the decimal representation of a binary number, I can just do this: int('11',2) # returns 3 But d

Re: Binary Decimals in Python

2010-03-30 Thread MRAB
John Nagle wrote: aditya wrote: On Mar 30, 10:49 am, Raymond Hettinger wrote: On Mar 30, 8:13 am, aditya wrote: To get the decimal representation of a binary number, I can just do this: int('11',2) # returns 3 But decimal binary numbers throw a ValueError: int('1.1',2) # should return 1.5,

Re: Binary Decimals in Python

2010-03-30 Thread Grant Edwards
On 2010-03-30, John Nagle wrote: > Hex floats are useful because you can get a string representation of > the exact value of a binary floating point number. It should always > be the case that > >float.fromhex(float.hex(x)) == x Until you try running your program on a machine that repre

Re: Binary Decimals in Python

2010-03-30 Thread Mensanator
On Mar 30, 10:49 am, Raymond Hettinger wrote: > On Mar 30, 8:13 am, aditya wrote: > > > To get the decimal representation of a binary number, I can just do > > this: > > > int('11',2) # returns 3 > > > But decimal binary numbers throw a ValueError: > > > int('1.1',2) # should return 1.5, throws e

Re: Binary Decimals in Python

2010-03-30 Thread John Nagle
aditya wrote: On Mar 30, 10:49 am, Raymond Hettinger wrote: On Mar 30, 8:13 am, aditya wrote: To get the decimal representation of a binary number, I can just do this: int('11',2) # returns 3 But decimal binary numbers throw a ValueError: int('1.1',2) # should return 1.5, throws error instea

Re: Binary Decimals in Python

2010-03-30 Thread Steven D'Aprano
On Tue, 30 Mar 2010 08:28:50 -0700, Patrick Maupin wrote: > On Mar 30, 10:13 am, aditya wrote: >> To get the decimal representation of a binary number, I can just do >> this: >> >> int('11',2) # returns 3 >> >> But decimal binary numbers throw a ValueError: >> >> int('1.1',2) # should return 1.5,

Re: Binary Decimals in Python

2010-03-30 Thread aditya
On Mar 30, 10:49 am, Raymond Hettinger wrote: > On Mar 30, 8:13 am, aditya wrote: > > > To get the decimal representation of a binary number, I can just do > > this: > > > int('11',2) # returns 3 > > > But decimal binary numbers throw a ValueError: > > > int('1.1',2) # should return 1.5, throws e

Re: Binary Decimals in Python

2010-03-30 Thread aditya
On Mar 30, 10:37 am, Benjamin Kaplan wrote: > On Tue, Mar 30, 2010 at 11:13 AM, aditya wrote: > > To get the decimal representation of a binary number, I can just do > > this: > > > int('11',2) # returns 3 > > > But decimal binary numbers throw a ValueError: > > > int('1.1',2) # should return 1.5

Re: Binary Decimals in Python

2010-03-30 Thread MRAB
aditya wrote: To get the decimal representation of a binary number, I can just do this: int('11',2) # returns 3 But decimal binary numbers throw a ValueError: int('1.1',2) # should return 1.5, throws error instead. Is this by design? It seems to me that this is not the correct behavior. int

Re: Binary Decimals in Python

2010-03-30 Thread Grant Olson
Doh! Well the problem is that int's are integers. So yeah, you can't even do that with normal value "int ('2.1')" will also throw an error. And floats don't support radix conversion, because no-one really writes numbers that way. (At least computer programmers...) On 3/30/2010 11:43 AM, Shash

Re: Binary Decimals in Python

2010-03-30 Thread Raymond Hettinger
On Mar 30, 8:13 am, aditya wrote: > To get the decimal representation of a binary number, I can just do > this: > > int('11',2) # returns 3 > > But decimal binary numbers throw a ValueError: > > int('1.1',2) # should return 1.5, throws error instead. > > Is this by design? It seems to me that this

Re: Binary Decimals in Python

2010-03-30 Thread Shashwat Anand
The conversion is not supported for decimal integers AFAIK, however '0b123.456' is always valid. I guess you can always get a decimal number convertor onto Python-recipes On Tue, Mar 30, 2010 at 9:05 PM, Grant Olson wrote: > On 3/30/2010 11:13 AM, aditya wrote: > > To get the decimal represent

Re: Binary Decimals in Python

2010-03-30 Thread Benjamin Kaplan
On Tue, Mar 30, 2010 at 11:13 AM, aditya wrote: > To get the decimal representation of a binary number, I can just do > this: > > int('11',2) # returns 3 > > But decimal binary numbers throw a ValueError: > > int('1.1',2) # should return 1.5, throws error instead. > > Is this by design? It seems t

Re: Binary Decimals in Python

2010-03-30 Thread Grant Olson
On 3/30/2010 11:13 AM, aditya wrote: > To get the decimal representation of a binary number, I can just do > this: > > int('11',2) # returns 3 > > But decimal binary numbers throw a ValueError: > > int('1.1',2) # should return 1.5, throws error instead. > > Is this by design? It seems to me tha

Re: Binary Decimals in Python

2010-03-30 Thread Patrick Maupin
On Mar 30, 10:13 am, aditya wrote: > To get the decimal representation of a binary number, I can just do > this: > > int('11',2) # returns 3 > > But decimal binary numbers throw a ValueError: > > int('1.1',2) # should return 1.5, throws error instead. > > Is this by design? It seems to me that thi

Re: Binary Decimals in Python

2010-03-30 Thread Shashwat Anand
decimal binary number is not included AFAIK On Tue, Mar 30, 2010 at 8:43 PM, aditya wrote: > To get the decimal representation of a binary number, I can just do > this: > > int('11',2) # returns 3 > > But decimal binary numbers throw a ValueError: > > int('1.1',2) # should return 1.5, throws err

Binary Decimals in Python

2010-03-30 Thread aditya
To get the decimal representation of a binary number, I can just do this: int('11',2) # returns 3 But decimal binary numbers throw a ValueError: int('1.1',2) # should return 1.5, throws error instead. Is this by design? It seems to me that this is not the correct behavior. - Aditya -- http://

Re: Decimals in python

2008-06-17 Thread Ethan Furman
[EMAIL PROTECTED] wrote: Hello. New to using Python. Python automatically round off watver i calculate using the floor function. How wud i make the exact value appear? Tried out fabs() in the math library but still confused. Cud some1 elaborate on it. [python] ---help(math.floor): Help on buil

Re: Decimals in python

2008-06-15 Thread Aidan
[EMAIL PROTECTED] wrote: Hello. New to using Python. Python automatically round off watver i calculate using the floor function. How wud i make the exact value appear? Tried out fabs() in the math library but still confused. Cud some1 elaborate on it. If you're working with integers, the resul

Decimals in python

2008-06-15 Thread arslanburney
Hello. New to using Python. Python automatically round off watver i calculate using the floor function. How wud i make the exact value appear? Tried out fabs() in the math library but still confused. Cud some1 elaborate on it. -- http://mail.python.org/mailman/listinfo/python-list