::——————————————————-
::please use quotes (“”) around the input
::——————————————————-
::running from cmd:
::hex “Hello World!”
::——————————————————-
::running from the .bat file:
::input=”Hello World!”
::——————————————————-
::output-string=48 65 6C 6C 6F 20 57 6F 72 6C 64
::——————————————————-
::I was unable to escape ^, so please dont use it 🙂
::——————————————————-
::set fulloutput to 0 if you only want the input & output
::——————————————————-
set fullouput=0
setlocal EnableDelayedExpansion
set string=%1
::removes double “” at the end of %string%
set string=%string:~0,-1%
::removes the double “” at the start of %string%
set string=%string:~1,31%
call :strlen iamount String
set line=—
set ln=———–
set lncount=0
:llloop
set ln=%ln%%line%
if ‘%linecount%’==’%iamount%’ goto nexxt
set /a linecount=%linecount%+1
goto llloop
:strlen
(
setlocal
set “s=!%~2!#”
set “len=0”
for %%P in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do (
if “!s:~%%P,1!” NEQ “” (
set /a “len+=%%P”
set “s=!s:~%%P!”
)))
(
endlocal
set “%~1=%len%”
exit /b
)
:nexxt
echo %ln%-
echo Input=Â Â Â Â Â Â %string%
if ‘%fullouput%’==’1’ echo Chars=Â Â Â Â Â Â %iamount%
if ‘%fullouput%’==’1’ echo %ln%
:cont
set i=0
set j=1
:loop1
set char%j%=!!string:~%i%,1!!
if ‘%fullouput%’==’1’ echo Char%j%=Â Â Â Â Â Â !char%j%!
if ‘%j%’==’%iamount%’ goto endloop1
set /a i=%i%+1
set /a j=%j%+1
goto loop1
:endloop1
if ‘%fullouput%’==’1’ echo %ln%-
::set counter
set n=1
:hex
if ‘!char%n%!’==’^ ‘ set chardec%n%=32
if ‘!char%n%!’==’^!’ set chardec%n%=33
if ‘!char%n%!’==’^”‘ set chardec%n%=34
if ‘!char%n%!’==’^#’ set chardec%n%=35
if ‘!char%n%!’==’^$’ set chardec%n%=36
if ‘!char%n%!’==’%%’ set chardec%n%=37
if ‘!char%n%!’==’^&’ set chardec%n%=38
if ‘!char%n%!’==’^” set chardec%n%=39
if ‘!char%n%!’==’^(‘ set chardec%n%=40
if ‘!char%n%!’==’^)’ set chardec%n%=41
if ‘!char%n%!’==’^*’ set chardec%n%=42
if ‘!char%n%!’==’^+’ set chardec%n%=43
if ‘!char%n%!’==’^,’ set chardec%n%=44
if ‘!char%n%!’==’^-‘ set chardec%n%=45
if ‘!char%n%!’==’^.’ set chardec%n%=46
if ‘!char%n%!’==’^/’ set chardec%n%=47
if ‘!char%n%!’==’0’ set chardec%n%=48
if ‘!char%n%!’==’1’ set chardec%n%=49
if ‘!char%n%!’==’2’ set chardec%n%=50
if ‘!char%n%!’==’3’ set chardec%n%=51
if ‘!char%n%!’==’4’ set chardec%n%=52
if ‘!char%n%!’==’5’ set chardec%n%=53
if ‘!char%n%!’==’6’ set chardec%n%=54
if ‘!char%n%!’==’7’ set chardec%n%=55
if ‘!char%n%!’==’8’ set chardec%n%=56
if ‘!char%n%!’==’9’ set chardec%n%=57
if ‘!char%n%!’==’^:’ set chardec%n%=58
if ‘!char%n%!’==’^;’ set chardec%n%=59
if ‘!char%n%!’==’^<‘ set chardec%n%=60
if ‘!char%n%!’==’^=’ set chardec%n%=61
if ‘!char%n%!’==’^>’ set chardec%n%=62
if ‘!char%n%!’==’^?’ set chardec%n%=63
if ‘!char%n%!’==’^@’ set chardec%n%=64
if ‘!char%n%!’==’A’ set chardec%n%=65
if ‘!char%n%!’==’B’ set chardec%n%=66
if ‘!char%n%!’==’C’ set chardec%n%=67
if ‘!char%n%!’==’D’ set chardec%n%=68
if ‘!char%n%!’==’E’ set chardec%n%=69
if ‘!char%n%!’==’F’ set chardec%n%=70
if ‘!char%n%!’==’G’ set chardec%n%=71
if ‘!char%n%!’==’H’ set chardec%n%=72
if ‘!char%n%!’==’I’ set chardec%n%=73
if ‘!char%n%!’==’J’ set chardec%n%=74
if ‘!char%n%!’==’K’ set chardec%n%=75
if ‘!char%n%!’==’L’ set chardec%n%=76
if ‘!char%n%!’==’M’ set chardec%n%=77
if ‘!char%n%!’==’N’ set chardec%n%=78
if ‘!char%n%!’==’O’ set chardec%n%=79
if ‘!char%n%!’==’P’ set chardec%n%=80
if ‘!char%n%!’==’Q’ set chardec%n%=81
if ‘!char%n%!’==’R’ set chardec%n%=82
if ‘!char%n%!’==’S’ set chardec%n%=83
if ‘!char%n%!’==’T’ set chardec%n%=84
if ‘!char%n%!’==’U’ set chardec%n%=85
if ‘!char%n%!’==’V’ set chardec%n%=86
if ‘!char%n%!’==’W’ set chardec%n%=87
if ‘!char%n%!’==’X’ set chardec%n%=88
if ‘!char%n%!’==’Y’ set chardec%n%=89
if ‘!char%n%!’==’Z’ set chardec%n%=90
if ‘!char%n%!’=='[‘ set chardec%n%=91
if ‘!char%n%!’==’\’ set chardec%n%=92
if ‘!char%n%!’==’]’ set chardec%n%=93
if ‘!char%n%!’==’^^’ set chardec%n%=94
if ‘!char%n%!’==’^_’ set chardec%n%=95
if ‘!char%n%!’==’^`’ set chardec%n%=96
if ‘!char%n%!’==’a’ set chardec%n%=97
if ‘!char%n%!’==’b’ set chardec%n%=98
if ‘!char%n%!’==’c’ set chardec%n%=99
if ‘!char%n%!’==’d’ set chardec%n%=100
if ‘!char%n%!’==’e’ set chardec%n%=101
if ‘!char%n%!’==’f’ set chardec%n%=102
if ‘!char%n%!’==’g’ set chardec%n%=103
if ‘!char%n%!’==’h’ set chardec%n%=104
if ‘!char%n%!’==’i’ set chardec%n%=105
if ‘!char%n%!’==’j’ set chardec%n%=106
if ‘!char%n%!’==’k’ set chardec%n%=107
if ‘!char%n%!’==’l’ set chardec%n%=108
if ‘!char%n%!’==’m’ set chardec%n%=109
if ‘!char%n%!’==’n’ set chardec%n%=110
if ‘!char%n%!’==’o’ set chardec%n%=111
if ‘!char%n%!’==’p’ set chardec%n%=112
if ‘!char%n%!’==’q’ set chardec%n%=113
if ‘!char%n%!’==’r’ set chardec%n%=114
if ‘!char%n%!’==’s’ set chardec%n%=115
if ‘!char%n%!’==’t’ set chardec%n%=116
if ‘!char%n%!’==’u’ set chardec%n%=117
if ‘!char%n%!’==’v’ set chardec%n%=118
if ‘!char%n%!’==’w’ set chardec%n%=119
if ‘!char%n%!’==’x’ set chardec%n%=120
if ‘!char%n%!’==’y’ set chardec%n%=121
if ‘!char%n%!’==’z’ set chardec%n%=122
if ‘!char%n%!’==’^{‘ set chardec%n%=123
if ‘!char%n%!’==’^|’ set chardec%n%=124
if ‘!char%n%!’==’^}’ set chardec%n%=125
if ‘!char%n%!’==’^~’ set chardec%n%=126
if ‘%n%’==’%iamount%’ set n=1&goto final
set /a n=%n%+1
goto hex
:final
if ‘%fullouput%’==’1’ echo Chardec%n%=Â Â Â !chardec%n%!
if ‘%n%’==’%iamount%’ (
set n=1
if ‘%fullouput%’==’1’ echo %ln%-
goto convert
)
set /a n=%n%+1
goto final
:convert
set input=!chardec%n%!
set /a modulo=%input%/16
set /a leftover=%input%-(%modulo%*16)
if %modulo% gtr 15 goto skip
if ‘%leftover%’==’15’ set hex2=F
if ‘%leftover%’==’14’ set hex2=E
if ‘%leftover%’==’13’ set hex2=D
if ‘%leftover%’==’12’ set hex2=C
if ‘%leftover%’==’11’ set hex2=B
if ‘%leftover%’==’10’ set hex2=A
if ‘%leftover%’==’9’ set hex2=9
if ‘%leftover%’==’8’ set hex2=8
if ‘%leftover%’==’7’ set hex2=7
if ‘%leftover%’==’6’ set hex2=6
if ‘%leftover%’==’5’ set hex2=5
if ‘%leftover%’==’4’ set hex2=4
if ‘%leftover%’==’3’ set hex2=3
if ‘%leftover%’==’2’ set hex2=2
if ‘%leftover%’==’1’ set hex2=1
if ‘%leftover%’==’0’ set hex2=0
set hex1=%modulo%
set charhex%n%=%hex1%%hex2%
if ‘%fullouput%’==’1’ echo Charhex%n%=Â Â Â 0x!charhex%n%!
if ‘%n%’==’%iamount%’ echo %ln%-&set n=1&goto output
set /a n=%n%+1
goto convert
:output
set “outputstring=!outputstring! !charhex%n%!”
if ‘!n!’==’!iamount!’ echo Output=Â Â Â Â Â Â Â Â Â !outputstring!&echo %ln%-&exit /b
set /a n=!n!+1
goto output
Related Posts
Add A Comment