开发者

How to execute exclusive-OR operation programmatically

How can I programmatically on Java execute next operation:

开发者_高级运维

The two blocks are exclusive-OR added:

05 92 38 9F FF FF FF FF
00 00 40 00 00 12 34 56
--------------------------------
05 92 78 9F FF ED CB A9

Thanks in advance.


The exclusive-or operator is ^, e.g.:

a = 1 ^ 2;

Assuming your first two rows are arrays, simply create a third array of the same dimension and loop through performing the operation and saving the result. (Or loop through performing the operation and storing back to one of the arrays, if you don't need a separate result array.)


You can use the XOR operator on the two blocks of bits. The bitwise XOR operator in Java is ^

http://download.oracle.com/javase/tutorial/java/nutsandbolts/op3.html


You want to use Java's Bitwise XOR Operator ^.

A   ^    B     =   C

1        0         1
0        1         1
0        0         0
1        1         0
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜