data-conversion - 如何在 python 3.7 中将 ascii 字符串更改为十六进制,反之亦然?
问题描述
我在这个网站上寻找了一些解决方案,但那些在 python 3.7 中不起作用。所以,我问了一个新问题。
“the”的十六进制字符串是“746865”
我想要一个将“the”转换为“746865”和“746865”转换为“the”的解决方案
解决方案
#!/usr/bin/python3
"""
Program name: txt_to_ASC.py
The program transfers
a string of letters -> the corresponding
string of hexadecimal ASCII-codes,
eg. the -> 746865
Only letters in [abc...xyzABC...XYZ] should be input.
"""
print("Transfer letters to hex ASCII-codes")
print("Input range is [abc...xyzABC...XYZ].")
print()
string = input("Input set of letters, eg. the: ")
print("hex ASCII-code: " + " "*15, end = "")
def str_to_hasc(x):
global glo
byt = bytes(x, 'utf-8')
bythex = byt.hex()
for b1 in bythex:
y = print(b1, end = "")
glo = str(y)
return glo
str_to_hasc(string)
推荐阅读
- python - 我想使用列表作为参数从函数的结果中创建一个列表
- google-sheets - Google 表格转到表格快捷方式
- firebase - 如何在 Firestore 规则中访问文档 ID
- javascript - Redux 工具包:createAsyncThunk 操作已分派并返回被拒绝的承诺,该操作返回空有效负载
- java - 如何从java中现有的特定JButton变量中检索字符串值调用?
- android - 我如何解决android studio中的安装问题
- c# - 避免在许多用户控件中重复相同的 EventTriggers
- python - 不和谐.py | 静音命令的未知问题
- function - 递归调用私有方法
- python - 为什么我在使用 selfbot 运行命令时收到错误“send() got an unexpected keyword argument”?