我看到如下代码,非常精辟!求老师指点!
@echo off&setlocal enabledelayedexpansion
:: 代码5
:: Code by CN-DOS terse
set "hx=0123456789ABCDEF"
set/p str=:
for /l %%i in (1 1 8) do (
if !str! GTR 0 (
set/a "n=str&15,str>>=4"
call set h=%%hx:~!n!,1%%!h!
)
)
if not defined h set "h=0"
echo.%str% 的十六进制为:0x!h!
pause
1,
%%i 是从1取到8,为什么?却没有看到%%i 的去处?
2,
set/a "n=str&15,str>>=4"
是取余的意思,但怎么也看不懂.....
如果按我的写法却成了这样:
set /a y= str%%16
set /a ya=str/16%%16
set /a yb=str/256%%16
set /a yc=str/4096%%16
set /a yd=str/65536%%16
set /a ye=str/1048576%%16
set /a yf=str/16777216%%16
set /a yg=str/268435456%%16
set m=0123456789ABCDEF
set cdm=!m:~%yg%,1!!m:~%yf%,1!!m:~%ye%,1!!m:~%yd%,1!!m:~%yc%,1!!m:~%yb%,1!!m:~%ya%,1!!m:~%y%,1!
[ Last edited by ZJHJ on 2010-8-18 at 00:36 ]
@echo off&setlocal enabledelayedexpansion
:: 代码5
:: Code by CN-DOS terse
set "hx=0123456789ABCDEF"
set/p str=:
for /l %%i in (1 1 8) do (
if !str! GTR 0 (
set/a "n=str&15,str>>=4"
call set h=%%hx:~!n!,1%%!h!
)
)
if not defined h set "h=0"
echo.%str% 的十六进制为:0x!h!
pause
1,
%%i 是从1取到8,为什么?却没有看到%%i 的去处?
2,
set/a "n=str&15,str>>=4"
是取余的意思,但怎么也看不懂.....
如果按我的写法却成了这样:
set /a y= str%%16
set /a ya=str/16%%16
set /a yb=str/256%%16
set /a yc=str/4096%%16
set /a yd=str/65536%%16
set /a ye=str/1048576%%16
set /a yf=str/16777216%%16
set /a yg=str/268435456%%16
set m=0123456789ABCDEF
set cdm=!m:~%yg%,1!!m:~%yf%,1!!m:~%ye%,1!!m:~%yd%,1!!m:~%yc%,1!!m:~%yb%,1!!m:~%ya%,1!!m:~%y%,1!
[ Last edited by ZJHJ on 2010-8-18 at 00:36 ]

