You Are Here:

Community: Developer Discussion Boards

#1 Old decode hex using raw input? - 2008-04-02, 17:08

Join Date: Mar 2008
Posts: 7
gormmark
Offline
Registered User
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
Reply With Quote

#2 Old Re: decode hex using raw input? - 2008-04-02, 18:42

Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
bogdan.galiceanu's Avatar
bogdan.galiceanu
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.
Reply With Quote

#3 Old Re: decode hex using raw input? - 2008-04-02, 19:17

Join Date: Mar 2008
Posts: 7
gormmark
Offline
Registered User
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?
Reply With Quote

#4 Old Re: decode hex using raw input? - 2008-04-02, 19:29

Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
bogdan.galiceanu's Avatar
bogdan.galiceanu
Offline
Forum Nokia Champion
Quote:
Originally Posted by gormmark View Post
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?
Sorry, I forgot to assign the decoded value to a. I've edited my post and it should work now.
Reply With Quote

#5 Old Re: decode hex using raw input? - 2008-04-02, 19:42

Join Date: Mar 2008
Posts: 7
gormmark
Offline
Registered User
Hia i tried the new code you edited but this time it only returns the a thats been assigned to it
Reply With Quote

#6 Old Re: decode hex using raw input? - 2008-04-02, 19:52

Join Date: Mar 2008
Posts: 7
gormmark
Offline
Registered User
Quote:
Originally Posted by gormmark View Post
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.
Reply With Quote

#7 Old Re: decode hex using raw input? - 2008-04-02, 19:52

Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
bogdan.galiceanu's Avatar
bogdan.galiceanu
Offline
Forum Nokia Champion
You're very welcome, glad I was able to help.
Reply With Quote

#8 Old Re: decode hex using raw input? - 2008-06-09, 23:49

Join Date: Mar 2003
Posts: 115
Dansco
Offline
Regular Contributor
Quote:
Originally Posted by bogdan.galiceanu View Post
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
Sorry to bring this up but I've tried this and it comes up with an error if I try and enter the value of 00611C I'm trying to convert HEX to an int or string.
Reply With Quote

#9 Old Re: decode hex using raw input? - 2008-06-10, 06:11

Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
bogdan.galiceanu's Avatar
bogdan.galiceanu
Offline
Forum Nokia Champion
Quote:
Originally Posted by Dansco View Post
I'm trying to convert HEX to an int or string.
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)
As for the conversion to string, this might work:
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
Reply With Quote

#10 Old Re: decode hex using raw input? - 2008-06-10, 17:25

Join Date: Mar 2003
Posts: 115
Dansco
Offline
Regular Contributor
Quote:
Originally Posted by bogdan.galiceanu View Post
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)
As for the conversion to string, this might work:
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
Cheers mate. I found out how to do it by total accident but thanx for the help
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
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

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d81449X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZpythonQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZuserE5ftagQSxpythonX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ