Ohk, heres a step by step of your code:
@echo off
Turns Echo
off meaning any commands executed can't be seen by the user, instead only input and output can be seen
setlocal EnableDelayedExpansion
Allows the use of !
to Expand Variables if %
has already been Expanded
set hexa=0123456789ABCDEF
Creates a variable hexa
with value of all valid hexadecimal digits.
set /P "first=Enter first color (hexa digit): "
Takes one line of input prompting with the above text, and sets first
to it.
set /P "second=Enter second color (hexa digit): "
Takes one line of input prompting with the above text, and sets seconds
to it.
set /A sum= (0x%first% + 0x%second%) %% 16
creates a variable sum
which is set to the solution to the above equation
set result=!hexa:~%sum%,1!
Creates a variable result
which is set to hexa
, from the sum
th index and one letter ahead.
color %result%
sets the screen colour to the hexadecimal value of result
echo The result is: %result%
Outputs to the console the above text including the value of the variable result
.
That explains it quite well, and if you want this code to do something else, feel free the ask.
Mona.