Code: Select all
@echo off
title Hex2Ascii converter
setlocal enabledelayedexpansion
pushd %temp%
:Start
:: Reset varaibles
set Counter=0
set AsciiCode=
ser AsciiCode_Puffer=
set DecimalCode
set BinaryCode=
set HexCode=
:: Ask for hexadecimal code
set /p HexCode=Hex:
set HexCode=%HexCode:0x=%
:: Check the beginning and the ending
if "%HexCode:~0,1%" == "{" set Counter=1
echo !HexCode! | find "}" >nul 2>null || set HexCode=!HexCode! {p8UyY}
:Conversion
set AsciiCode_Puffer=!AsciiCode!
::Check if finished
if "!HexCode:~%Counter%,1!" == "}" goto :Finished
if "!HexCode:~%Counter%,9!" == " p8UyY" goto :Finished
:: Check for symbols and spaces
if "HexCode:~%Counters%,1!" == "-" set /a Counter=%Counter% + 1 & goto :Conversion
if "HexCode:~%Counters%,1!" == " " set /a Counter=%Counter% + 1 & goto :Conversion
if "HexCode:~%Counters%,1!" == "," set /a Counter=%Counter% + 1 & goto :Conversion
if "HexCode:~%Counters%,1!" == "|" set /a Counter=%Counter% + 1 & goto :Conversion
if "HexCode:~%Counters%,1!" == "." set /a Counter=%Counter% + 1 & goto :Conversion
if "HexCode:~%Counters%,1!" == ":" set /a Counter=%Counter% + 1 & goto :Conversion
if "HexCode:~%Counters%,1!" == ";" set /a Counter=%Counter% + 1 & goto :Conversion
:: Start of conversion from hex to ascii
if "!HexCode:~%Counters%,2!" == "00" set /a Counter=%Counter% + 2 & set AsciiCode=!AsciiCode!{NUL}& set DecimalCode=!DecimalCode!0, & set BinaryCode=!BinaryCode!00000000
if "!HexCode:~%Counters%,2!" == "01" set /a Counter=%Counter% + 2 & set AsciiCode=!AsciiCode!SOH& set DecimalCode=!DecimalCode!1, & set BinaryCode=!BinaryCode!00000001
if "!HexCode:~%Counters%,2!" == "02" set /a Counter=%Counter% + 2 & set AsciiCode=!AsciiCode!STX& set DecimalCode=!DecimalCode!2, & set BinaryCode=!BinaryCode!00000010
if "!HexCode:~%Counters%,2!" == "03" set /a Counter=%Counter% + 2 & set AsciiCode=!AsciiCode!ETX& set DecimalCode=!DecimalCode!3, & set BinaryCode=!BinaryCode!00000011
if "!HexCode:~%Counters%,2!" == "04" set /a Counter=%Counter% + 2 & set AsciiCode=!AsciiCode!EOT& set DecimalCode=!DecimalCode!4, & set BinaryCode=!BinaryCode!00000100
if "!HexCode:~%Counter%,2!" == "05" set /a Counter=%Counter% + 2 & set AsciiCode=!AsciiCode!ENQ& set DecimalCode=!DecimalCode!5, & set BinaryCode=!BinaryCode!00000101
if "!HexCode:~%Counter%,2!" == "06" set /a Counter=%Counter% + 2 & set AsciiCode=!AsciiCode!ACK& set DecimalCode=!DecimalCode!6, & set BinaryCode=!BinaryCode!00000110
if "!HexCode:~%Counter%,3!" == "07" set /a Counter=%Counter% + 2 & set AsciiCode=!AsciiCode!BEL& set DecimalCode=!DecimalCode!7, & set BinaryCode=!BinaryCode!00000111
if "!HexCode:~%Counter%,2!" == "08" set /a Counter=%Counter% + 2 & set AsciiCode=!AsciiCode!BS& set DecimalCode=!DecimalCode!8, & set BinaryCode=!BinaryCode!00001000
if "!HexCode:~%Counter%,2!" == "09" set /a Counter=%Counter% + 2 & set AsciiCode=!AsciiCode! & set DecimalCode=!DecimalCode!9, & set BinaryCode=!BinaryCode!00001001
if /i "!HexCode:~%Counter%,2!" == "0a" set /a Counter=%Counter% + 2 & set AsciiCode=!AsciiCode!{LF}& set DecimalCode=!DecimalCode!10, & set BinaryCode=!BinaryCode!00001010
if /i "!HexCode:~%Counter%,2!" == "0b" set /a Counter=%Counter% + 2 & set AsciiCode=!AsciiCode!VT& set DecimalCode=!DecimalCode!11, & set BinaryCode=!BinaryCode!00001011
if /i "!HexCode:~%Counter%,2!" == "0c" set /a Counter=%Counter% + 2 & set AsciiCode=!AsciiCode!FF& set DecimalCode=!DecimalCode!12, & set BinaryCode=!BinaryCode!00001100
if /i "!HexCode:~%Counter%,2!" == "0d" set /a Counter=%Counter% + 2 & set AsciiCode=!AsciiCode!FF& set DecimalCode=!DecimalCode!13, & set BinaryCode=!BinaryCode!00001101
if /i "!HexCode:~%Counter%,2!" == "0e" set /a Counter=%Counter% + 2 & set AsciiCode=!AsciiCode!FF& set DecimalCode=!DecimalCode!14, & set BinaryCode=!BinaryCode!00001110
if /i "!HexCode:~%Counter%,2!" == "0f" set /a Counter=%Counter% + 2 & set AsciiCode=!AsciiCode!FF& set DecimalCode=!DecimalCode!15, & set BinaryCode=!BinaryCode!00001111
:Finished
echo !HexCode! | find "p8UyY" >nul 2>nul && set HexCode=!HexCode:!
if "!HexCode:~0,1!" == "{" set AsciiCode={!AsciiCode!&set DecimalCode {
if "!HexCode:~-1,1!" == "}" set AsciiCode={!AsciiCode!}&set DecimalCode
echo Hex: !HexCode! 1>Hex2Ascii.tmp
echo Dec: !DecimalCode! 1>>Hex2Ascii.tmp
echo Dec: !AsciiCode! 1>>Hex2Ascii.tmp
echo Bin: !BinaryCode! 1>>Hex2Ascii.tmp
pause
start notepad "%temp%\Hex2Ascii.tmp"
echo Dec: !DecimalCode!
echo Ascii: !AsciiCode! ^<- in CMD
echo Bin: !BinaryCode!
echo.
echo.
goto :Start