Skip to content

Instantly share code, notes, and snippets.

@huggre

huggre/hex_convert.py

Last active Mar 17, 2020
Embed
What would you like to do?
Helper for converting an IOTA address to a C++ hex array
# Imports the textrwap library
from textwrap import wrap
# Replace with your own IOTA payment address
sample = 'NYZBHOVSMDWWABXSACAJTTWJOQRPVVAWLBSFQVSJSWWBJJLLSQKNZFC9XCRPQSVFQZPBJCJRANNPVMMEZQJRQSVVGZ'
# Create a list with 4 characters in each element
mylist = wrap(sample,4)
result = ''
# Convert each element in the list to hex separated by ,
for i in mylist:
result=result + '0x' + i.encode("utf-8").hex() + ','
# Remove last , from string
result=result[:-1]
# Append the curly brackets
result = '{' + result + '}'
# Print the resulting string
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.