Re: hex string to hex value

2005-11-23 Thread [EMAIL PROTECTED]
Fredrik Lundh wrote: > [EMAIL PROTECTED] wrote: > > > Fredrik Lundh's solution works if the hex string starts with "0x" > > that's what "interpret [it] as a Python literal" meant. I know from personal experience that the implications of that sometimes go right over the head of a newbie. Did I do

Re: hex string to hex value

2005-11-22 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > Fredrik Lundh's solution works if the hex string starts with "0x" that's what "interpret [it] as a Python literal" meant. > (which it will when the string is created with the hex function). > > >>> int(hex(m),0) > 66 > > But it won't work without the "0x". > > >>> int(

Re: hex string to hex value

2005-11-22 Thread Grant Edwards
On 2005-11-23, tim <[EMAIL PROTECTED]> wrote: >int(hex(m),16) > > >>66 >> >>Fredrik Lundh's solution works if the hex string starts with "0x" >>(which it will when the string is created with the hex function). >> > aren't you converting from a hex string to a decimal value here

Re: [Fwd: Re: hex string to hex value]

2005-11-22 Thread tim
Brett g Porter wrote: > tim wrote: > >> >> I end up with 66 again, back where I started, a decimal, right? >> I want to end up with 0x42 as being a hex value, not a string, so i >> can pas it as an argument to a function that needs a hex value. >> (i am trying to replace the 0x42 in the line >>

Re: [Fwd: Re: hex string to hex value]

2005-11-22 Thread Brett g Porter
tim wrote: > > I end up with 66 again, back where I started, a decimal, right? > I want to end up with 0x42 as being a hex value, not a string, so i can > pas it as an argument to a function that needs a hex value. > (i am trying to replace the 0x42 in the line midi.note_off(channel=0, > note=0

Re: [Fwd: Re: hex string to hex value]

2005-11-22 Thread Rocco Moretti
tim wrote: > ok, but if i do > > >>> n=66 > >>> m=hex(n) > >>> m > '0x42' > >>> h=int(m,16) > >>> h > 66 > >>> > > I end up with 66 again, back where I started, a decimal, right? > I want to end up with 0x42 as being a hex value, not a string, so i can > pas it as an argument to a function

Re: hex string to hex value

2005-11-22 Thread tim
[EMAIL PROTECTED] wrote: >tim wrote: > > >>but then i get : >> >> >>> m >>66 >> >>> n=int(hex(m)) >>Traceback (most recent call last): >> File "", line 1, in ? >>ValueError: invalid literal for int(): 0x42 >> >>> >> >>what am I missing here ? >> >> > >Avnit's solution was wrong. When conve

Re: hex string to hex value

2005-11-22 Thread [EMAIL PROTECTED]
tim wrote: > but then i get : > > >>> m > 66 > >>> n=int(hex(m)) > Traceback (most recent call last): > File "", line 1, in ? > ValueError: invalid literal for int(): 0x42 > >>> > > what am I missing here ? Avnit's solution was wrong. When converting a string, you must state what base you ar

[Fwd: Re: hex string to hex value]

2005-11-22 Thread tim
ok, but if i do >>> n=66 >>> m=hex(n) >>> m '0x42' >>> h=int(m,16) >>> h 66 >>> I end up with 66 again, back where I started, a decimal, right? I want to end up with 0x42 as being a hex value, not a string, so i can pas it as an argument to a function that needs a hex value. (i am trying t

Re: hex string to hex value

2005-11-22 Thread [EMAIL PROTECTED]
avnit wrote: > If you just want to convert a string to an integer, it would be: > > >>> int(n) That's what the OP tried and it didn't work. BECAUSE you have to tell the int function what base the string is in (even though it has "0x" at the start). >>> int(n,16) 66 > > in your case it would be

Re: hex string to hex value

2005-11-22 Thread tim
but then i get : >>> m 66 >>> n=int(hex(m)) Traceback (most recent call last): File "", line 1, in ? ValueError: invalid literal for int(): 0x42 >>> what am I missing here ? thank you Tim avnit wrote: >If you just want to convert a string to an integer, it would be: > > > int(n)

Re: hex string to hex value

2005-11-22 Thread Fredrik Lundh
"tim" <[EMAIL PROTECTED]> wrote: > This is probably another newbie question...but... > even after reading quite some messages like '..hex to decimal', > 'creating a hex value' , I can't figure this out: > If i do > >>> m=66 > >>> n=hex(m) > >>> n > '0x42' > i cannot use n as value for a variable t

Re: hex string to hex value

2005-11-22 Thread avnit
If you just want to convert a string to an integer, it would be: >>> int(n) in your case it would be: >>> m=66 >>> n=int(hex(m)) -- http://mail.python.org/mailman/listinfo/python-list

hex string to hex value

2005-11-22 Thread tim
This is probably another newbie question...but... even after reading quite some messages like '..hex to decimal', 'creating a hex value' , I can't figure this out: If i do >>> m=66 >>> n=hex(m) >>> n '0x42' i cannot use n as value for a variable that takes hex values, because it throws: error