mirror of
https://github.com/RustyRaptor/ProgrammingLanguages.git
synced 2026-12-03 21:55:15 -07:00
added python code to generate array setter
This commit is contained in:
1 parent
55099a5af9
commit
034deaf806
1 file changed
+38
@@ -0,0 +1,38 @@
|
||||
from binascii import hexlify
|
||||
|
||||
|
||||
name = "Ziad Arafat" # The string you wanna print
|
||||
|
||||
"""
|
||||
Converts an input string to it's respective hex in Little endian as a string
|
||||
"""
|
||||
def str_to_hex(i_string):
|
||||
return hexlify(i_string.encode()).decode()
|
||||
|
||||
|
||||
"""
|
||||
prints out all the array assignment lines for a given string.
|
||||
"""
|
||||
def string_to_hexes(i_string):
|
||||
commands = []
|
||||
# i_string = i_string[::-1]
|
||||
print(i_string)
|
||||
|
||||
array_idx = 0 # index on the array
|
||||
|
||||
# loop through the input string and print out the line every 4 letters
|
||||
for key, val in enumerate(i_string):
|
||||
if key % 4 == 0:
|
||||
commands.append("A["+str(array_idx)+"] = 0x" +
|
||||
str_to_hex(i_string[key:key+4][::-1]))
|
||||
array_idx += 1
|
||||
|
||||
# print out the null character at the end
|
||||
commands.append("A[" + str(array_idx)+"] = 0")
|
||||
print(commands)
|
||||
|
||||
for i in commands:
|
||||
print(i + ";")
|
||||
|
||||
|
||||
string_to_hexes(name)
|
||||
Reference in new issue
Block a user