DOS批处理脚本字符串转换成2进制 [英] DOS Batch script to convert string 2 hex

查看:1071
本文介绍了DOS批处理脚本字符串转换成2进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何可以转换SRING在DOS批处理脚本诅咒?
例如,转换ABCD到61626364。
一直以来,'一'是0x61 ...

我试图找到从网站,每天的解决方案,也没有找到我的答案。


解决方案

 关闭@echo
SETLOCAL EnableDelayedExpansionREM存放在chr.tmp文件中的字符串
集/ P=%〜1< NUL> chr.tmpREM具有相同数量的的Ascii零字符创建zero.tmp文件
对于一个%%在(chr.tmp)做FSUTIL文件createnew zero.tmp %%〜杂志> NULREM比较FC / B这两个文件并获得差异
集六角=
FOR / F跳过= 1令牌= 2%%一中(FC / B chr.tmp zero.tmp')不设置六角=!六角!%%一个德尔chr.tmp zero.tmp
回声%六角%

输出例如:

  C:\\> test.bat的ABCD
61626364

How can I convert sring to hex in DOS Batch script? For example, convert "abcd" to "61626364". Since, 'a' is 0x61...

I tried to find a solution from web, a day, but could not find my answer.

解决方案

@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%

Output example:

C:\> test.bat abcd
61626364

这篇关于DOS批处理脚本字符串转换成2进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆