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

Bitwise math/Operators/AND

From NetSec
Revision as of 07:29, 19 July 2012 by GertieUbpgdd (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
back to Bitwise math


c3el4.png
AND returns “TRUE” per true bit in both of the required two operands. True is 1 and false is 0. It operates bit by bit, just like NOT.

AND rules

AND compares each bit and if both bits per placeholder are true, then it returns a true for that placeholder, all else gets turned into 0.
  • 1 and 1 = 1
  • 1 and 0 = 0
  • 0 and 0 = 0

AND properties

  • anything AND'd by itself results in itself
  • anything AND'd with 0xF results in itself
  • anything AND'd with 0x0 results in 0x0

AND example

Example: 0x6 AND 0x5 = 0x4
Operation Hexadecimal Binary comment


and

6

5

0110

0101

The second and third bits are true.

The second and fourth bits are true.

=
4 0100 The second bit is the only one true in both instances (5 and 6).

AND logic table

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