the adventures of a small software engineer in a big universe

Applicable Uses of the XOR Operator

Today I’m here to talk about my love affair with the logical Exclusive-Or (XOR). Some pronounce is “ex-or”, others pronounce it “ZOR”. Either way, I am dedicating my time this year to blogging about bit manipulation. I do this in hope that some soul out there, digging up boolean algebra topics like I did, will stumble across my work. I hope I can provide engaging material to somebody out there, who shares in my fascination with bit manipulation.

As a primer, for those of you who are unfamiliar with boolean algebra, or for those who need a refresher:

What is the logical XOR?

An XOR is an operator. There are operators in arithmetic that you’re definitely familiar with. 
+, −, ÷, ×

The addition operator +, takes two inputs, and yields one result.

Inputs of 1, and 2, and the operator +, will always result in 3. When you see the +, you know that you will add the two values together.

The XOR operator has two inputs, and one output as well. This is a common way that XOR is represented: 

Rather than accepting base 10 values (1,2,3,…9), it accepts inputs that are either true or false. Each input will be either a 1 or a 0.

The rules for an XOR operator are simple.

Differing inputs will always yield a 1 (TRUE). 0 ⊕ 1 == 1

Now we will move onto the interesting stuff. I’ll go over some use-cases of the XOR in computing.


  1. CHECKSUM (Network Security)
  2. RAID Drive Backups (Systems)


Case 1. Checksum

What is a checksum?

Its a method of confirming the integrity of a file, after it has been in transit. A checksum is a mathematical output that will help you confirm whether or not a file has been corrupted or tampered with.

Suppose you have a file, it could be an mp3, a jpg or even an executable. The file needs to transfer from a local machine to a remote machine. If the receiver wanted to ensure this was a trusted file, we can confirm its integrity through a checksum. Every file is composed of unique binary data. If even a single character is missing, or changed from the original string of binary data, the entire file is corrupted.

The binary data of an mp3 in my computer 🙂

When a file is being transferred from server A to server B, its cut into blocks, sent over piece by piece, then re-attached at its destination. To ensure each block is not corrupted, a checksum function is ran on it, generating a unique CHECKSUM. All of these ASCII symbols are then interpreted in base 2 (1’s and 0’s), and each chunk is XOR-ed together.

What is the outcome?

This gives us a XOR result, or a unique checksum string of 1’s and 0’s. When the file is reattached and written to disk on the other server, it can reference the checksum generated by the source server, to ensure it hasn’t been corrupted. In the above example, if the file had not been corrupted during transit (downloading), the checksum of your downloaded copy would’ve been identical to the checksum of the original file on the server.

Case 2. RAID Drive Backups

Nowadays, nearly every household has an external hard drive, and backs up computer files in some manner. You can never predict what will happen tomorrow, so its better to safe than sorry and backup your files.

A standard user will make a 1:1 backup, meaning for every set of files, you will create one backup on a form of external memory.

But what happens when you are in the business of data warehousing, and are responsible for thousands of hard drives? The naive solution would be to create one backup for every one set of user files. Thus for 300 hard drives, you will create 300 backups. This works, but it will become very expensive, very quickly.

Let’s go over a thought experiment. What if I told you that instead of purchasing N disk drives to back up N servers (filled at capacity), we could do it in < N? I’m here to introduce an industry-standard hard disk configuration known as RAID 5.

For simplicity’s sake, lets pretend we have very tiny disks, which have a capacity of 8 bytes each. Each disk is nearly full, and holds a single text file.

Here are the three files:

File descriptions, size, and contents of the three servers
Binary translation of the file contents of the three servers

Thanks to the magical property of XOR, all three of these server’s contents can be recovered through, not three backup hard drives, but one single parity drive. The XOR will work in a similar fashion to the checksum we covered in the previous case. When we XOR together the contents of the three hard drives, we get the following:

The XOR contents of the three disks. Let’s keep this parity disk somewhere safe, in the event of an emergency…

Tomorrow, a disk failure happens with server 2. The contents of server 2 have gone missing. How do we recover it? We crack open the parity disk, which contains the XOR of the three servers. Hidden inside “01101001 00100111 01101101 00111111 01100111 01101001 01100101 01101000 00001010” is the original content of the destroyed server.

How do we fish back out the data of server 2 from this parity disk? The key to retrieving it is to use server 1 and server 3, its partners in creating the parity disk.

We will XOR together the binary data of:

  • File 1
  • File 3
  • Parity Disk

To obtain the original contents of:

  • File 2

The rest is all mathematical.

File 1 ⊕ File 3 ⊕ Parity Disk == Recovered Data

Using these seemingly mysterious properties of XOR, we have managed to recover the contents of server 2.

Assuming in a world with minimal complications, we don’t lose more than 1 input disk at a time, out of these groups of 3 servers, we could backup an entire data center of 300 disks, using only 100, as opposed to 300. We could do even less than 100, if we wanted to risk it at XOR more disks together, etc. But keep in mind, one fault of RAID5 is that if you lose more than 1 disk in a grouping, the parity disk will become useless. There are some other recovery solutions you can architect in the event of a disaster, but thats a conversation for a future article, when I move into a systems architecture discussion. 🙂

If you’re interested in more bit manipulation content, I’ll have some future posts coming up! More surprises yet to come…

-Claire Y. Li, Computer Scientist

Leave me a comment! :)


beans said:
2019-02-16 01:08:25

"BYTE 💖😍🤪"

киногоо said:
2019-04-10 20:46:53

"Howdy would you mind letting me know which webhost you're working with? I've loaded your blog in 3 completely different web browsers and I must say this blog loads a lot faster then most. Can you suggest a good hosting provider at a reasonable price? Thanks, I appreciate it!"

where can i buy viagra pills said:
2019-04-19 16:24:21

"I know this web page gives quality depending posts and other data, is there any other site which gives these kinds of information in quality?"

MatExhabe said:
2019-05-07 07:49:14

"Propecia Cartelera Free Viagra Without Prescription brand levitra canada Amoxicillin Package Insert"

MatExhabe said:
2019-05-13 03:20:21

"Dosis Kamagra Gel Il Cialis Funziona Sempre Viagra Que Pasa Si buy viagra Quanto Costa Il Cialis 10 Mg"

StevGedy said:
2019-07-30 19:57:43

"Sildenafil Generique 120 Mg Strep Throat Antibiotic Dose Amoxicillin Viagra Cialis Acquisto viagra online pharmacy Viagra Ahnliche Tabletten Precios De Cialis Vendo Viagra Annunci"

hzyphj said:
2019-08-02 10:17:42

"il levitra fa male agli occhi buy levitra viagra online"

StevGedy said:
2019-08-05 20:04:53

"Is Keflex A Beta Cialis Funciona En Mujeres cialis prix public Propecia Once Per Day Amoxicillin 500 Mg Generic"

KennySib said:
2019-08-14 19:31:45

"Advance Checking USA is an online marketplace that connects those looking allowing for regarding payday loans with a network of lenders."

EllLoth said:
2019-08-15 12:39:47

"Viagra Pastiglie Morbide Antibiotics Thecanadiandrugstore cialis without prescription Sildenafil Citrate 250mg Prix Viagra 50 100 Mg"

Mindy said:
2019-09-03 10:04:16

"Hi, very nice website, cheers! ------------------------------------------------------ Need cheap and reliable hosting? Our shared plans start at $10 for an year and VPS plans for $6/Mo. ------------------------------------------------------ Check here:"

Deedee said:
2019-09-04 12:46:58

"Hi, very nice website, cheers! ------------------------------------------------------ Need cheap and reliable hosting? Our shared plans start at $10 for an year and VPS plans for $6/Mo. ------------------------------------------------------ Check here:"

Ava said:
2019-09-04 13:27:18

"Hi, very nice website, cheers! ------------------------------------------------------ Need cheap and reliable hosting? Our shared plans start at $10 for an year and VPS plans for $6/Mo. ------------------------------------------------------ Check here:"

Bretthix said:
2019-09-07 00:45:26

"metformin hcl 500 mg without prescription"

BennyDough said:
2019-09-08 06:26:07

"propranolol 120 mg"

BennyDough said:
2019-09-10 14:46:54

"buy accutane"

Cindyujaceva said:
2019-09-10 16:51:49

"cialis 5mg generic for cialis"

Cindyesaceva said:
2019-09-10 21:10:12

"buy cialis buy cheap tadalafil cialis tadalafil"

Cindyumaceva said:
2019-09-10 23:22:20

"buy cialis zoloft price generic cialis online"

Cindyimaceva said:
2019-09-11 03:51:09

"cialis 5 mg cialis generic tadalafil generic cialis tadalafil"

Cindyrcaceva said:
2019-09-11 07:31:38

"cialis usa cialis without prescription cialis 5mg"

Cindyuwaceva said:
2019-09-11 09:18:08

"cialis without prescription viagra online cialis without a prescription"

Cindymcaceva said:
2019-09-11 11:19:55

"generic cialis online viagra generico funciona mesmo cialis for bph"

Bretthix said:
2019-09-11 12:45:39

"buy accutane"

Cindyqqaceva said:
2019-09-11 13:22:13

"buy generic cialis online zoloft prices cialis coupon"

Cindynuaceva said:
2019-09-11 15:52:24

"cialis prices online pharmacy viagra cialis"

Cindyosaceva said:
2019-09-11 18:48:11

"generic cialis setraline purchase cialis online"

Cindybaaceva said:
2019-09-11 22:01:16

"order cialis online paroxetine cialis vs viagra"

Cindyfyaceva said:
2019-09-12 00:06:06

"cialis cost paxil prices cialis without prescription"

BennyDough said:
2019-09-12 00:12:41

"finasteride prices"

Cindyepaceva said:
2019-09-12 04:19:00

"cialis pills generic for viagra cialis without prescription"

Cindygsaceva said:
2019-09-13 10:52:13

"cialis dosage when will generic viagra be available cialis cost"

Cindyhsaceva said:
2019-09-13 13:22:55

"buy cialis pills best generic cialis generic cialis"

BennyDough said:
2019-09-13 14:56:38

"albuterol hfa"

Cindythaceva said:
2019-09-13 16:17:08

"buy cialis buy tadalafil cialis cialis for sale"

BennyDough said:
2019-09-14 05:11:07

"mail order levitra pills"

Cindyvzaceva said:
2019-09-14 16:03:18

"cialis from canada ed solutions cialis dosage"

Cindygiaceva said:
2019-09-15 04:54:24

"cialis 20mg viagra for men cialis tadalafil"

Cindywxaceva said:
2019-09-15 09:27:23

"buy cialis generic paxil cialis for sale"

Cindyzjaceva said:
2019-09-16 01:47:31

"generic cialis ed pills cialis 20mg"

Cindyeraceva said:
2019-09-16 06:31:02

"cialis online prilosec vs nexium cialis without prescription"

BennyDough said:
2019-09-16 21:47:13

"generic drug for viagra"

Douglashox said:
2019-09-17 07:42:07

"advair diskus generic"

Bretthix said:
2019-09-17 07:53:13

"purchase prozac online"

BennyDough said:
2019-09-17 18:08:37

"metformin 500 mg without prescription"

Cindyssaceva said:
2019-09-18 06:54:10

"buy generic cialis online nexicom webmail cialis super active"

Bretthix said:
2019-09-19 03:31:19


canadianpharmacyndamus said:
2019-09-19 10:13:38

"canadian generic viagra review cheap viagra online canadian pharmacy online pharmacy canada cheap viagra online canadian pharmacy"

BennyDough said:
2019-09-19 14:55:04

"inderal propranolol"

Cindymvaceva said:
2019-09-19 16:51:34

"cialis for women generic cialis india cialis canada"

cout << "hello world";

Hello there! My name is Claire Li. I’m a 24 year old computer scientist! This blog is for recording my experiences in the Bay Area as a software engineer, and writing my thoughts on topics I am passionate about. So far, expect to hear about logical operators, networks, discrete math, cryptography, embedded systems, and hardware hobby projects.

For now, here’s a clip of the first apartment that I stayed in, when starting work in Silicon Valley!

Leave me a comment! :)


Lex said:
2019-09-04 12:13:27

"Hi, very nice website, cheers! ------------------------------------------------------ Need cheap and reliable hosting? Our shared plans start at $10 for an year and VPS plans for $6/Mo. ------------------------------------------------------ Check here:"