How to convert string “0671” or “0x45” into integer form with 0 and 0x in the beginning

只愿长相守 提交于 2020-01-16 11:25:34

问题


I wanted to make my own encryption algorithm and decryption algorithm , encryption algorithm works fine and converts ascii value of the characters into alternate hexadecimal and octal representations. But when I tried decryption, problem occured as it return int('0671') = 671, as 0671 is string type in the following code. Is there a method to convert "ox56" into integer form??????

NOTE: Following string is alternate octal and hexa of ascii value of char.

///////////////DECRYPTION///////

l="01630x7401620x6901560x67"
f=len(l)
k=0
d=0
x=[]

for i in range(0,f,4):
  g=l[i:i+4]
  print g 
  k=k+1   
  if(k%2==0):
  p=g
  print p
  else:
  p=int(g)
  print p

回答1:


there you go (s is the string)

int(s,0)


来源:https://stackoverflow.com/questions/3045202/how-to-convert-string-0671-or-0x45-into-integer-form-with-0-and-0x-in-the-be

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!