Hexadecimal Conversion in Python

James Stroud jstroud at mbi.ucla.edu
Wed Nov 2 16:55:14 EST 2005


On Wednesday 02 November 2005 12:53, DaBeef wrote:
> I have been coding for 5 years.  This is a proprietary protocol, so it
> is difficult converting.  I did this in java but was just able to
> convert a stream.  I looked through the Python library, I am more or
> less getting backa  string represented as a "...."   So now I want to
> convert it to all the hexa, bin until I see a match and can then work
> teh rest of my program

Its great that you are learning python, but it seems you are confused about 
how it works, so you are not making sense to a lot of people. Hex conversion 
can be done in a lot of ways. You should look into "struct" as others have 
suggested, which might be a more resource effecient (less processor cycles) 
choice and also give you your data as numerical types. If you have managed to 
get to the point of having a string that looks like this:

       '\xcb\xdb\xbe\xef'

Then the simplest thing for you to do (least amount of learning) at this point 
might be to look at "decode" and "encode"

for example

       >>> hex_rep = '\xcb\xdb\xbe\xef'.encode('hex')
       >>> print hex_rep
       'cbdbbeef'

Also, you might annoy (read: 'you have annoyed') a lot of people by saying 
that python has a "llimited" library. Not only are you incorrect, but you 
made a typo. You will do well to learn as much of the python library as you 
can, but it will take some time. You will also do well to avoid typos and 
grammatical errors in your communications.

Also, you need to answer Fredrik's question. Let me restate it. What do you 
mean by '....'? This encodes in hex to '2e2e2e2e'. Is this the cipher text 
you were expecting? If so, your company may want to re-think its encryption 
algorithm.

James

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/



More information about the Python-list mailing list