|
|
发表于 2025-10-31 02:10:39
|
显示全部楼层
0x31 0x32 0x33是十六禁止的1、2、3,具体发送和接收转换方式可以参考:local str = string.char(0x31) .. string.char(0x32) .. string.char(0x33),然后得到的str变量就是123了。至于将38转出:-- 原始字符串
local str = "38"
-- 存储结果的变量
local hexResult = ""
-- 循环处理每个字符
for i = 1, #str do
-- 拼接字符转换为十六进制并拼接
hexResult = hexResult .. string.format("0x%02X", string.byte(str, i))
-- 如果不是最后一个字符,添加分隔符
if i < #str then
hexResult = hexResult .. ", "
end
end
-- 循环结束后,hexResult就是最终结果变量
print(hexResult) -- 输出:0x31, 0x32, 0x33 |
|