Questions about this topic? Sign up to ask in the talk tab.

Bitwise math/Operators/XOR

From NetSec
Jump to: navigation, search
back to Bitwise math


c3el4.png
XOR is a bitwise comparison operator that returns a true bit if the compared bits in question are different. If they are the same, it returns a false bit.

XOR rules

XOR determines which bits differ in the two binary numbers used as operands.
  • 1 xor 1 = 0
  • 1 xor 0 = 1
  • 0 xor 0 = 0

XOR properties

  • Anything xor'd with itself results in 0
  • Anything xor'd with 0xF is the same as a "not"
  • Anything xor'd with zero results in itself

XOR example

Example: A xor F = 5
Operation Hexadecimal Binary comment


xor

A

F

1010

1111

The first and third bits are true.

The first, second, third, and fourth bits are true.

=
5 0101 The second and fourth bits are true in ONLY one instance as opposed to two.
  • The 8’s and 2's placeholders are the same so they return 0.
  • The 4’s and 1’s placeholders are different, therefore return true.

XOR logic table

XOR 0 1 2 3 4 5 6 7 8 9 A B C D E F
0 0 1 2 3 4 5 6 7 8 9 A B C D E F
1 1 0 3 2 5 4 7 6 9 8 B A D C F E
2 2 3 0 1 6 7 4 5 A B 8 9 E F C D
3 3 2 1 0 7 6 5 4 B A 9 8 F E D C
4 4 5 6 7 0 1 2 3 C D E F 8 9 A B
5 5 4 7 6 1 0 3 2 D C F E 9 8 B A
6 6 7 4 5 2 3 0 1 E F C D A B 8 9
7 7 6 5 4 3 2 1 0 F E D C B A 9 8
8 8 9 A B C D E F 0 1 2 3 4 5 6 7
9 9 8 B A D C F E 1 0 3 2 5 4 7 6
A A B 8 9 E F C D 2 3 0 1 6 7 4 5
B B A 9 8 F E D C 3 2 1 0 7 6 5 4
C C D E F 8 9 A B 4 5 6 7 0 1 2 3
D D C F E 9 8 B A 5 4 7 6 1 0 3 2
E E F C D A B 8 9 6 7 4 5 2 3 0 1
F F E D C B A 9 8 7 6 5 4 3 2 1 0