string - DOS批处理脚本转换字符串2十六进制

标签 string batch-file hex character dos

如何在 DOS 批处理脚本中将字符串转换为十六进制? 例如,将“abcd”转换为“61626364”。 因为,'a' 是 0x61...

我一天试图从网络上寻找解决方案,但找不到答案。

最佳答案

@echo off
setlocal EnableDelayedExpansion

rem Store the string in chr.tmp file
set /P "=%~1" < NUL > chr.tmp

rem Create zero.tmp file with the same number of Ascii zero characters
for %%a in (chr.tmp) do fsutil file createnew zero.tmp %%~Za > NUL

rem Compare both files with FC /B and get the differences
set "hex="
for /F "skip=1 tokens=2" %%a in ('fc /B chr.tmp zero.tmp') do set "hex=!hex!%%a"

del chr.tmp zero.tmp
echo %hex%

输出示例:

C:\> test.bat abcd
61626364

关于string - DOS批处理脚本转换字符串2十六进制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35077030/

相关文章:

java - 从批处理文件的进程中读取 InputStream 会跳到下一行

.net - 如何在没有外部软件的情况下使用批处理脚本将二进制文件拆分为一定大小的 block ?

无法计算出 C 中指针的十六进制转换

C# 转换十六进制值

android - 无法访问 'split' : it is private in file

javascript - 正则表达式获取两个字符串之间的所有字符串

Windows 批处理 : findstr not setting ERRORLEVEL within a for loop

python - "Unpack requires a string argument of length 4"解包时 float ?

java - 如何在java中的另一个字符串中的特定字符后添加一个字符串?

python - 我的 Python 中的空字符串检测?