- @echo off&color 1f&title 十六进制 转 二进制
- set mmm=56D6A2E9A8F098F23F6453ADCFC87775D9311CBC
- call :16x2 %mmm% ok
- echo.&echo 十六进制 %mmm%
- echo.&echo 二进制 %ok%
- echo.&pause&exit
-
- ::以4位一段,分别转换为二进制,不必考虑超大数问题
- :16x2 十六进制 转 二进制 @随风 @bbs.bathome.net (封装)
- @echo off&setlocal enabledelayedexpansion
- set str=0123456789abcdef&set ok=&set "num=%~1"
- for /l %%a in (0 1 15) do (set ".!str:~%%a,1!=%%a"
- call set "num=%%num:!str:~%%a,1!= !str:~%%a,1!%%")
- for %%i in (!num!) do (set /a x=0,n=!.%%i!
- for %%a in (8 4 2 1) do (set /a x+=%%a
- if !n! geq !x! (set ok=!ok!1) else (
- set ok=!ok!0&set /a x-=%%a)))
- endlocal&set %~2=%ok%&goto :EOF
复制代码
|