john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

CMD command line math

msdos can do math (Four-byte signed arithmetic )

set /a 2+2 //displays the result on the screen set /a 2*(9/2) set /a "31>>2" //bit shifting

set /a x=9
echo %x% set /a y=2+2 //assigns the result to the variable set /a x+y //shows the result of the 2 variables

C:>set /a 0x1234 //hex to decimal conversion 4660

C:>set /a 31^>^>2 //the ^ acts as an escape operator so that you can shift bits 7

set /? for help with the 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

  • « CMD notes
  • c sharp express to wss 3 webpart »

Published

Feb 6, 2010

Category

research

~144 words

Tags

  • cmd 14
  • command 29
  • line 31
  • math 2
  • research 199