Incrementing (iterating) between two hex values in Python -
i'm learning python (slowly surely) need write program (among other things) increments between 2 hex values e.g. 30d681 , 3227ff. i'm having trouble finding best way this. far have seen snippet of code on here separates hex 30, d6 , 81, works this-
char = 30 char2 = d6 char3 = 81 def doublehex(): global char,char2,char3 x in range(255): char = char + 1 = str(chr(char)).encode("hex") p in range(255): char2 = char2 + 1 b = str(chr(char2)).encode("hex") y in range(255): char3 = char3 + 1 b = str(chr(char2)).encode("hex") c = a+" "+b print "test:%s"%(c) doublehex()
is there simpler way of incrementing whole value, e.g. like
char = 30d681 char2 = 3227ff def doublehex(): global char,char2 x in range(255): char = char + 1 = str(chr(char)).encode("hex") p in range(255): char2 = char2 + 1 b = str(chr(char2)).encode("hex") c = a+" "+b print "test:%s"%(c) doublehex()
apologies complete ignorance, have tried googling answer couldn't find it...
just treat values integers, , use xrange()
range on 2 values. use format(value, 'x')
display hex:
start = 0x30d681 # hex literal, gives regular integer end = 0x3227ff in xrange(start, end + 1): print format(i, 'x')
if start , end values entered hexadecimal strings, use int(hexvalue, 16)
turn integers first:
start = int('30d681', 16) end = int('3227ff', 16)