Command Promot (DOS) Calculation: An unknown tip

Do you very often use the DOS interface of Windows and love to invent new tips or command for DOS; then here is one…. which I hope you should like… using DIS interface to type numerical calucations.

Now open Command Prompt using the start menu or through the Windows Run menu (Windows Logo key + r) type cmd and press enter this will open command prompt…

Type cd\ to go to root directory… now notice the following calculations to understand more

C:\>set /a 2+2
4
C:\>set /a 2*(9/2)
8
C:\>set /a (2*9)/2
9
C:\>set /a “31>>2”
7

However; you can also do some more with this set command for a complete list type set /? to find complete set of command as shown below:

C:\>set /?
Displays, sets, or removes cmd.exe environment variables.

SET [variable=[string]]

  variable  Specifies the environment-variable name.
  string    Specifies a series of characters to assign to the variable.

Type SET without parameters to display the current environment variables.

If Command Extensions are enabled SET changes as follows:

SET command invoked with just a variable name, no equal sign or value
will display the value of all variables whose prefix matches the name
given to the SET command.  For example:

    SET P

would display all variables that begin with the letter ‘P’

SET command will set the ERRORLEVEL to 1 if the variable name is not
found in the current environment.

SET command will not allow an equal sign to be part of the name of
a variable.

Two new switches have been added to the SET command:

    SET /A expression
    SET /P variable=[promptString]

The /A switch specifies that the string to the right of the equal sign
is a numerical expression that is evaluated.  The expression evaluator
is pretty simple and supports the following operations, in decreasing
order of precedence:

    ()                  – grouping
    ! ~ –               – unary operators
    * / %               – arithmetic operators
    + –                 – arithmetic operators
    << >>               – logical shift
    &                   – bitwise and
    ^                   – bitwise exclusive or
    |                   – bitwise or
    = *= /= %= += -=    – assignment
      &= ^= |= <<= >>=
    ,                   – expression separator

Leave a Reply

Your email address will not be published. Required fields are marked *