Bitwise Operators

MathParser.org - mXparser - logo - Tutorial

*** If you found the software useful donation is something you might consider 🙂 ***

If you found the software useful donation is something you might consider :-)

JAVA code

Case 1: Bitwise unary complement

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("@~2");
mXparser.consolePrintln("Res: " + e.getExpressionString() + " = " + e.calculate() );
[mXparser-v.4.0.0] Res: @~2 = -3.0

Case 2: Bitwise AND

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("10 @& 2");
mXparser.consolePrintln("Res: " + e.getExpressionString() + " = " + e.calculate() );
[mXparser-v.4.0.0] Res: 10 @& 2 = 2.0

Case 3: Bitwise exclusive OR

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("10 @^ 2");
mXparser.consolePrintln("Res: " + e.getExpressionString() + " = " + e.calculate() );
[mXparser-v.4.0.0] Res: 10 @^ 2 = 8.0

Case 4: Bitwise inclusive OR

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("10 @| 2");
mXparser.consolePrintln("Res: " + e.getExpressionString() + " = " + e.calculate() );
[mXparser-v.4.0.0] Res: 10 @| 2 = 10.0

Case 5: Signed left / right shift

import org.mariuszgromada.math.mxparser.*;
...
/*
 * Left shift
 */
Expression e1 = new Expression("10 @<< 2");
mXparser.consolePrintln("Res 1: " + e1.getExpressionString() + " = " + e1.calculate() );
/*
 * Right shift
 */
Expression e2 = new Expression("10 @>> 2");
mXparser.consolePrintln("Res 2: " + e2.getExpressionString() + " = " + e2.calculate() );
[mXparser-v.4.0.0] Res 1: 10 @<< 2 = 40.0
[mXparser-v.4.0.0] Res 2: 10 @>> 2 = 2.0

*** If you found the software useful donation is something you might consider 🙂 ***

If you found the software useful donation is something you might consider :-)

Enjoy! 🙂

 

Best regards,

Mariusz Gromada

Download latest release – v.4.1.1 Aeries: bin + doc + src (.zip 13.4 MB)

Download latest release – v.4.1.1 Aeries: bin only (.zip 4.35 MB) – separate binaries for java: 1.5, 1.6, 1.7, 1.8; .NET: 2.0, 3.0, 3.5, 4.0, 4.5, 4.6, 4.7, .NET Core, .NET Standard, .NET PCL, Xamarin.Android, Xamarin.iOS

Source code .zipSource code .tar.gz View on GitHubMathSpace.pl