I created a program that converts decimal to hexadecimal and binary, but I have a whole bunch of glitches.
One of the *current* glitches are "( was not expected", but when I looked through the code I couldn't find any unnecessary parenthesis.
Another says that "%chars:~!tempnumHEX!,1%%finalnumHEX%" isn't computable. It's supposed to get the modulus of an equation and use the variable chars to find the corresponding value of hexadecimal for it.
Though if I ignore the errors and type in "5" for the program to convert, it displays nothing for the hex and 01 for the binary. So I'm assuming the error takes place in the hexadecimal conversion part?
Thanks.
Code: Select all
@echo off
title Decimal to Binary ^& Hexadecimal
color 0b
setlocal EnableDelayedExpansion
set chars= 123456789ABCDEF
:ask
cls
set /p convertnumHEX=Number to convert:
set convertnumBIN=%convertnumHEX%
:main
::checks if it is done converting to hexadecimal
if %convertnumHEX%==0 (
::if done with hex, checks for binary
if %convertnumBIN%==0 (
::if done with binary, then goes to display results
goto :results
) else (
::otherwise, if it isnt done converting to binary
::it converts it
set /a modulusBIN=convertnumBIN %% 2
set /a convertnumBIN=convertnumBIN / 2
set finalnumBIN=%modulusBIN%%finalnumBIN%
::done with producing a digit of the binary
)) else (
::now this is when it isn't done converting to hexadecimal
set /a modulusHEX=convertnumHEX %% 16
set /a convertnumHEX=%convertnumHEX% / 16
set finalnumHEX=%chars:~!modulusHEX!,1%%finalnumHEX%
)
::goes back to main to check for any more needed conversions
goto :main
:results
echo hex %finalnumHEX%
echo bin %finalnumBIN%
pause