You are viewing a read-only archive of the Blogs.Harvard network. Learn more.

XOR

August 20th, 2012

if a ^ b

What the hell is that carrot doing there? ….It’s an “exclusive or”.

It’s the same as saying:

(a && !b) || (!a && b)

which also means…


a | b |
0 | 0 | f
0 | 1 | t
1 | 0 | t
1 | 1 | f

Damn, useful… sometimes.

Entry Filed under: Professional,Ruby on Rails

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>