# Converting String to a Hexadecimal value

Status
Not open for further replies.

#### shussai2

##### Programmer
I want to convert a string into a hex value without the quotations. So for example I have:

s='0x'
r='01'
sr=s+r

//when I print sr it gives me '0x01'

what I want to do is to convert it in hex value by getting rid of the quotations and just having value as 0x01.

Is there function which converts a string or another type of value in Hex without the quotations in there. Meaning it gives me just the value no string representation of hex.

Code:
``````Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on win32
>>> s='0x'
>>> r='01'
>>> sr = s+r
>>> sr
'0x01'
>>> print sr
0x01
>>> eval(sr)
1
>>> long(sr, 16)
1L
>>>``````

This brings up a point:

1 is a hexidecimal value.
0x01 is a string representation of the value 1 expressed in a common notation indicating that you are operating in base 16.

What are you trying to accomplish?

Well I was trying to use PIL to get particular pixels in a bitmap. But after I posted this I figured out the solution given above. Although what I do is convert the equivalent s='0x01' into a int by using string conversion base to 16.

Status
Not open for further replies.

Replies
1
Views
101
Replies
2
Views
171
Replies
2
Views
104
Replies
27
Views
247
Replies
3
Views
104