Note (12/2015): Hi there! I'm taking some time off here to focus on other projects for a bit. As of October 2016, those other projects include a science book series for kids titled Things That Make You Go Yuck! -- available at Barnes and Noble, Amazon and (hopefully) a bookstore near you!

Co-author Jenn Dlugos and I are also doing some extremely ridiculous things over at Drinkstorm Studios, including our award-winning webseries, Magicland.

There are also a full 100 posts right here in the archives, and feel free to drop me a line at secondhandscience@gmail.com with comments, suggestions or wacky cold fusion ideas. Cheers!

XOR


· Categories: Computers, Mathematics
What I’ve Learned:

XOR: 'THERE CAN BE ONLY ODD NUMBERS OF THINGS!'
“XOR: ‘THERE CAN BE ONLY ODD NUMBERS OF THINGS!'”

If you look closely enough, even really complicated mathematics breaks down into simple logic. And if you look at simple logic closely enough… well, it’s really freaking complicated.

Take the word “or”. We use “or” between things all the time. Cake or pie. French fries or onion rings. Coffee, tea or milk.

(And also between things that aren’t food, probably. I skipped lunch, so I’ve got a bit of a one-track stomach right now.)

Mostly, our “or”s mean you can have one thing or the other — but that’s not always true. This is the 21st century, and we’re in ‘Murrica, dadgummit, so if you want half fries and half rings, you can have it. Milk in your coffee? No problem. You want a pie baked inside a cake, on top of another cake with a pie in it?

Well, of course you do. Because ‘Murrica.

These ambiguous “or”s are fine in conversation — and in diners, bakeries and burger joints, apparently — but they won’t do when it comes to math and logic. For that, you need something more specific. More restrictive. You need XOR.

XOR — or “exclusive or”, if you like — is a logical operator that denotes the less generous sort of “or”. XOR is “or” with a mean disciplinarian streak. It’s the Ebenezer Scrooge of “or”. The angry ruler-wielding Catholic nun of “or”. And when separating two choices, XOR is the big ugly punk highlander of “or”: THERE CAN BE ONLY ONE!

In logical terms, a pairwise XOR represents the choice of “A or B, but not A and B”. But this is logic, so it’s not that simple. You can slip XORs between any number of items — Bob XOR Carol XOR Ted XOR Alice, for instance — and in the general case, XOR is true when an odd number of things are true.

So XOR isn’t totally stingy, but you might not like the results. You can have any one of coffee, tea or milk — or you can have all three mixed together, because three is an odd number. Wake up and smell that in the morning, I dare you.

Outside of pure math operations, XOR has some interesting practical uses. It’s used when generating random numbers to ensure that “random” really is random. XOR is also used in cryptography, sometimes alone as a simple “XOR cipher”, but usually as part of a more complicated system.

And there’s something called an “XOR swap algorithm”, which I don’t actually understand at all, but I assume has something to do with Bob caking Alice’s pie while Carol milks Ted’s coffee. Or something.

The important thing is, there’s “or” and then there’s XOR. So if you’re offering someone a choice and feeling particularly stingy, Scroogy or Highlander-y, remember the “exclusive or” that the math and logic types use. Because “or” is fine — but XOR is delicious.

Actual Science:
University of Maryland CSThe magic of XOR
MalwarebytesNowhere to hide: three methods of XOR obfuscation
Logic.lyXOR gate
CCSIThe XOR problem and solution

Image sources: PSU / Teaching with Databases (XOR Venn), Flying Monkey Philly (pumpple cake, which is somehow actually a thing), The Daily Banter (shiny happy Kurgan), 429 (B, C, T, A)

· Tags: , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *