| Reply | « Previous Thread | Next Thread » |
|
hia guys, another n00b question lol
im using a simple way of decoding long hex strings at the moment: a = " hex code goes here ".decode("hex") print a but it means when i go to decode more hex i have delete all the hex iv entered into the script. I was wondering if there was a way to make this work using the raw_input command so i only have to run the script and enter the long hex strings to be decoded and save me the trouble of having to delete stuff from the script all the time. I tried using this : a = raw_input("Enter Hex Code :") b = ("%s") % a dec_hex = "b".decode("hex") print dec_hex But unfortunatly that doesnt work, can anyone point out where im going wrong here thanks |
|
Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
Offline
Forum Nokia Champion
|
|
Hi,
I tried this example and it worked: Code:
a=raw_input("Enter hex code:")
#Entered 00611C
a=a.decode("hex")
a #Returns \x00a\x1c
Last edited by bogdan.galiceanu : 2008-04-02 at 19:50.
|
|
Hia thanks for your reply bogdan, I tried the example you showed me but it only returned the 00611C that im entering? any idea why it wont work for me?
|
|
Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
Offline
Forum Nokia Champion
|
|
Sorry, I forgot to assign the decoded value to a. I've edited my post and it should work now.
|
|
Hia i tried the new code you edited but this time it only returns the a thats been assigned to it
|
|
its ok bogdan it was a user error by me lol its working now thanks very much for your help mate. much appreciared.
|
|
Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
Offline
Forum Nokia Champion
|
|
You're very welcome, glad I was able to help.
|
|
Quote:
I'm trying to convert HEX to an int or string. ![]() |
|
Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
Offline
Forum Nokia Champion
|
|
Here's a function for converting hex to int. I did a few tests with an online converter and the values returned by this function seem to be correct. Hope it helps:
Code:
def hex_to_int(s):
return int(s, 16)
Code:
def hex_to_str(s):
a=""
for i in range(len(s)/2):
r=i*2
a+=chr(int(s[r:r+2],16))
return a
Last edited by bogdan.galiceanu : 2008-06-10 at 07:03.
Reason: typo
|
|
Quote:
![]() |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Rate This Thread | |
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| Form 中怎么才能具有radio input \ text input 和 select input | liyongxiong | Symbian | 1 | 2006-03-29 12:23 |
| UIQ2.1 MultiViews & CEikEdwin handwrite input troubles? | goready@163.com | General Symbian C++ | 0 | 2005-10-16 10:19 |
| numeric input on nokia6820 | marcelk00l | Browsing and Mark-ups | 0 | 2004-07-16 15:43 |
| subscribing to Analog Input changes | fernanfr | Nokia M2M | 1 | 2003-03-04 11:32 |
| SMS from change in N30 input pin | vhkauppi | Nokia M2M | 2 | 1970-01-01 02:00 |