s1 = 'This is a test string'
# [ord(x) for x in s1] This list comprehension gives us a list of integer values for each character
# join takes a sequence of str() and joins them
' '.join([str(ord(x)) for x in s1])

"""
Explanation: Converting between Octal, Binary, Hex

ord
hex
chr
int
bin
format

Lets convert a string of characters into its unicode value for each character using list comprehension with ord and join method
End of explanation
"""


' '.join([format(ord(x)) for x in s1])

"""
Explanation: Lets convert a string of characters into its unicode value for each character using format and join method
End of explanation
"""


' '.join([format(ord(x), 'b') for x in s1])

"""
Explanation: What about a text string into binary
End of explanation
"""


' '.join([format(ord(x), 'b').zfill(8) for x in s1])

"""
Explanation: If we want it to be 8 bits long
End of explanation
"""


' '.join([format(ord(x), 'x') for x in s1])

"""
Explanation: What about a text string into hex using format and join
converting each character into its unicode ordinal value then format that result into a hex while joining each character into a string thats space seperated each value
End of explanation
"""


' '.join([format(ord(x), 'o') for x in s1])

"""
Explanation: What about a text string into octal
End of explanation
"""


ord?

# This is an integer value
ord('T')

"""
Explanation: ord()
Takes a single character and returns its unicode value
End of explanation
"""


hex(16)

"""
Explanation: hex()
Takes an integer and returns hexadecimal representation
End of explanation
"""


chr?

chr(84)

"""
Explanation: chr()
returns a unicode string of one character with ordinal i
End of explanation
"""


bin?

"""
Explanation: bin()
Takes an int and returns the binary representation
End of explanation
"""


int('0xDEADBEEF', 16)

int('DEADBEEF', 16)

int('DEADBEEF')

int('0oDEADBEEF', 16)

"""
Explanation: int
takes a number or string representing a number and a base and converts into an integer
When specifying a base, the first argument must be a string
With int you specify the base of the string, not the base your trying to convert to converts everything to ints
End of explanation
"""


chr(int('54', 16))

chr(int('124', 8))

chr(int('01010100', 2))

"""
Explanation: Given a hex/octal/binary number, how do you get the ascii/utf-8 string back

convert everything back to an int using int() and specifying the base
convert ints back into ordinal using chr()
End of explanation
"""


format?

format(x, 'x')

"""
Explanation: format
Specify how to format the output with base and size
End of explanation
"""


