この10進数を16進数と2進数のコンバーターに変換しています。16進数は10進数を16進数に変換し、バイナリ変換はそれを行います。10進数から16進数およびバイナリコンバータへバッチプログラム、どのように違う方法で実装するのですか?
これはうまくいきますが、このコードを実装する別の方法はありますか?
@echo off
setlocal EnableDelayedExpansion
:Main
setlocal
cls
set /p decIn=enter Decimal value:
call :DectoHex %decIn% hexOut
call :DectoBin %decIn% binOut
echo !hexOut!
echo !binOut!
pause>nul
goto :main
endlocal
::-------------------------------------------------------------------------------------
:DectoHex
set /a A=%1
set map=ABCDEF
set H=
:Hexloop
set /a B=!A! %%16 & set /a A /=16
set H=!map:~%B%,1!!H!
if !A! gtr 0 goto :Hexloop
set %2=!H!
goto :eof
::-------------------------------------------------------------------------------
:DectoBin
:: Note Dec Bit Bin (DBB)
set /a Dec=%1
set Bin=
for /L %%i in (1,1,32) do (
set /a "Bit=Dec&1, Dec>>=1"
set Bin=!Bit!!Bin!
)
:skimming
if %Bin:~0,1% == 0 (
set Bin=%Bin:~1% & goto :skimming
)
set %2=!Bin!
goto :eof
::-----------------------------------------------------------------------------
:BintoDec
set bin=11011
set dig=
set digval=1
set dec=
:Loop
if %bin% gtr 1 (
set dig=%bin:~-1%
set bin=%bin:~0,-1%
) else (
set /a dig=%bin%
set bin=0
)
if %dig% equ 1 (
set /a dec+=%digval%
)
set digval *=2
if %bin% gtr 0 goto :loop
echo %dec%
pause>nul
goto :eof
主な機能は、2と36の間の任意の数の基地へ/から変換するには、ユーザからの入力をrecieves 16進数変換器のパラメータとバイナリコンバータとして変数を渡し、
ので、あなたは可能性変換する基数を渡して、サブルーチンを1つだけ持ちます。 – LotPings
この質問は、[コードレビュースタックエクスチェンジ](https://codereview.stackexchange.com/)よりも、スタックオーバーフローより適しています。これは、ユーザーが実際に十進数(または16進数「0x」で始まる数字または「0」で始まる8進数)。 – Mofi