Last active
August 29, 2015 13:56
-
-
Save FlyingJester/9146349 to your computer and use it in GitHub Desktop.
[Python] Create a string that, when written to a binary file, represents a number. Also contains null-padding function for fixed-width representation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def StringifyKeepingValue(s): | |
stringy = "" | |
while s: | |
digit = s %256 | |
s-= s%256 | |
s = s/256 | |
stringy+=chr(digit) | |
return stringy | |
def PadString(val, s, l): | |
if len(s) == l: | |
return s | |
if len(s) > l: | |
return s [0:l] | |
while len(s) < l: | |
s=val+s | |
return s | |
def PadAndString(n, l): | |
return PadString(chr(0), StringifyKeepingValue(n), l) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment