By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,050 Members | 1,009 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,050 IT Pros & Developers. It's quick & easy.

How to convert string to long?

P: 30
hi,

is there a way to convert from string to long? for eg: i want to concatenate all the arrays into data and make it same type (long) as data1.

Expand|Select|Wrap|Line Numbers
  1. a='0x'
  2. array0 = '00000018000004000000000000000000'
  3. array1 = '00000000000000000000000000000000'
  4. array2 = 'fe000000000000000000000000000000'
  5. array3 = '00000000000000000000000000ffffff'
  6. data = a+array0+array1+array2+array3
  7. print data
  8. print type(data)
  9. data1 = 0x0000001800000400000000000000000000000000000000000000000000000000fe00000000000000000000000000000000000000000000000000000000ffffff
  10. print type(data1)
  11.  
  12.  
###result:
0x000000180000040000000000000000000000000000000000 0000000000000000fe00000000000000000000000000000000 000000000000000000000000ffffff
<type 'str'>
<type 'long'>
######

thanks
maximus
Feb 24 '11 #1
Share this Question
Share on Google+
1 Reply


P: 30
i found it but the leading zeroes are being truncated.
i want it to be: 0x000000180000040000000000000000000000000000000000 0000000000000000L

>>> array0='00000018000004000000000000000000'
>>> array1='00000000000000000000000000000000'
>>> array=array0+array1
>>> a=int(array,16)
>>> print a
64703872643936753210796946425631950553194187622978 5714677657987186688
>>> print hex(a)
0x180000040000000000000000000000000000000000000000 0000000000L
>>>
Feb 24 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.