Tools: How to do quick arithmetic from the command prompt?

 

The command processor CMD.EXE comes with a mini-calculator
that can perform simple arithmetic on 32-bit signed integers:

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

Note that we had to quote the shift operator since it would
otherwise be misinterpreted as a “redirect stdout and append” operator.

For more information, type set /? at the command prompt.
This item has taken from The Old New Thing

 
  • Harry Roland Kunz

    FOR THOSE WHO DON’T KNOW:
    if you want to add and save the value into an environmental variable use:
    C:>set /a myvar=2+2

    type: “set myvar” to display the result 4 or
    type: “echo myvar” = %myvar%
    (minus the quotes)