Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bmoregeo
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmoregeo/e44abbc5ddeb8c462462 to your computer and use it in GitHub Desktop.
Save bmoregeo/e44abbc5ddeb8c462462 to your computer and use it in GitHub Desktop.
def ExtractInt(string, start_position):
"""
Loop through string till the next + or - sign and convert the stuff in between from 32-> integer
"""
result = []
stop = False
position = start_position
while not stop:
char = string[position]
if not position == start_position and (char in ('-','+')):
stop = True
break
else:
result.append(char)
position+=1
if position == len(string):
stop = True
if len(result) >0:
iResult = stringToInt32(''.join(result))
final_position = position
return (iResult, final_position)
else:
ValueError(string)
def stringToInt32(string):
"""
Convert binary string to integer
"""
i = int(string[1:],32)
if string[0] == '-':
return -i
elif not string[0] in ('-','+'):
ValueError('Invalid String: %s' % string)
else:
return i
def parseBinaryGeo(string):
difX = 0
difY = 0
i = 0
while i < len(string):
nDiffX, i = ExtractInt(string, i)
print nDiffX, i
nDifYX, i = ExtractInt(string, i)
nX = nDiffX + nLastDiffX
nY = nDiffY + nLastDiff
print nX, nY
x = parseBinaryGeo(string)
print x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment