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! :)

(SHOW ALL COMMENTS)

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 http://levitranew.com 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. www.loansreviewsusa.com"

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: https://www.good-webhosting.com/"

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: https://www.good-webhosting.com/"

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: https://www.good-webhosting.com/"

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 http://cialissoftp.com/# 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

"inderal"

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"

Charlestit said:
2019-09-21 11:40:18

"vardenafil hcl 20mg "

canadianpharmacyndamus said:
2019-09-21 15:22:11

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

Cindynvaceva said:
2019-09-22 04:18:29

"buy cialis online tadalafil without prescription cialis for bph"

Cindytuaceva said:
2019-09-22 08:43:23

"buy generic cialis online cheapest place to buy vardenafil buy cialis now"

Cindyzyaceva said:
2019-09-22 18:32:22

"generic cialis buy vardenafil online without prescription cialis pills"

Cindyzgaceva said:
2019-09-24 21:52:01

"cheap cialis online buy cialis 5mg generic cialis"

Cindylmaceva said:
2019-09-25 01:55:16

"generic cialis 20mg buy vardenafil usa online generic cialis"

Cindyilaceva said:
2019-09-25 05:49:26

"cialis without a prescription erectile dysfunction drug generic cialis online"

Cindybfaceva said:
2019-09-25 09:42:29

"cialis 5 mg cialis prices"

Douglashox said:
2019-09-26 18:45:33

"cost of xenical at walmart "

canadianpharmacyndamus said:
2019-09-28 18:41:48

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

Herberttam said:
2019-09-30 09:22:16

"erectile pills from canada erectile pills without a doctor prescription erectile assistance buy erectile dysfunction meds online"

Douglashox said:
2019-09-30 23:18:04

"does lexapro cause seizures "

Herberttam said:
2019-10-01 05:05:39

"erectile aid device erectile dysfunction remedies erectile after you quit drinking buy erectile dysfunction pills online"

Herberttam said:
2019-10-01 05:56:11

"medication induced erectile dysfunction erectile pills without a doctor prescription erectile enhancement buy erectile dysfunction pills"

Herberttam said:
2019-10-01 22:46:38

"erectile disorder vs erectile dysfunction erectile dysfunction remedies erectile pills without side effects buy erectile dysfunction medications online"

btlkzvthxg said:
2019-10-01 23:53:39

"cialis coupon cialis no prescription cialis canada"

oxqydshgfo said:
2019-10-02 04:56:31

"buy cialis generic for lyrica buy cialis online"

saymcwasnh said:
2019-10-02 09:50:56

"cheap cialis lyrica withdrawal symptoms cialis price"

Douglashox said:
2019-10-04 14:13:25

"what company makes cialis "

Douglashox said:
2019-10-07 04:44:08

"pfizer zithromax 250 mg "

Herberttam said:
2019-10-07 04:44:27

"erectile breast tissue buy erectile dysfunction medications online how erectile dysfunction affects reproduction buy erectile dysfunction medications online"

canadianpharmacyndamus said:
2019-10-08 10:04:55

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

canadianpharmacyndamus said:
2019-10-09 05:39:29

"generic viagra canada pharmacy generic viagra online canadian pharmacy canadian pharmacy meds viagra online canadian pharmacy canada drugs online cheap viagra online canadian pharmacy canada online pharmacy generic viagra generic viagra online canadian pharmacy"

Douglashox said:
2019-10-09 05:48:11

"food poisoning prescription "

canadianpharmacyndamus said:
2019-10-09 06:14:05

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

Douglashox said:
2019-10-09 22:05:36

"price of amoxicillin liquid without insurance at cvs "

canadianpharmacyndamus said:
2019-10-10 11:22:33

"viagra online generic canada canadian pharmacy online viagra canadian pharmacy generic canadian pharmacy online canadian pharmacies canadian pharmacy online online canadian pharmacy canadian pharmacy generic viagra"

canadianpharmacyndamus said:
2019-10-11 11:29:40

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

Douglashox said:
2019-10-11 21:33:15

"business headquarters"

canadianpharmacyndamus said:
2019-10-12 01:03:50

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

canadianpharmacyndamus said:
2019-10-12 01:43:43

"canadian pharmacy viagra online canadian pharmacy canadian pharmacy online canadian pharmacy generic viagra canada online pharmacy generic viagra canadian pharmacy online online canadian pharmacy canadian pharmacy online"

Douglashox said:
2019-10-12 10:39:45

"business headquarters"

Cindykraceva said:
2019-10-12 11:41:23

"buy cialis now the canadian drugstore generic cialis 20mg"

canadianpharmacyndamus said:
2019-10-12 17:32:18

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

Cindyxiaceva said:
2019-10-12 17:42:40

"cialis tadalafil generic for nexium generic cialis online"

Cindyexaceva said:
2019-10-12 23:27:01

"cialis 20 mg http://btadalafil.com/ cialis coupon"

Cindylpaceva said:
2019-10-13 04:52:44

"acheter cialis cost of tadalafil cialis vs viagra"

canadianpharmacyndamus said:
2019-10-13 06:04:33

"canadian generic viagra canadian pharmacy online canadian pharmacy meds viagra online canadian pharmacy canadian pharmacy meds cheap viagra online canadian pharmacy viagra online canadian pharmacy generic viagra online canadian pharmacy"

canadianpharmacyndamus said:
2019-10-13 06:40:00

"canadian generic viagra viagra online canadian pharmacy canadian pharmacy viagra generic canadian pharmacy online canadian drug stores canadian pharmacy online canadian pharmacy meds generic viagra online canadian pharmacy"

Cindynjaceva said:
2019-10-13 10:17:36

"canadian cialis vardenafil dosage generic cialis online"

Douglashox said:
2019-10-13 13:30:40

"business"

Cindyadaceva said:
2019-10-13 16:08:40

"order cialis sildenafil online cialis canada"

canadianpharmacyndamus said:
2019-10-13 23:27:00

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

Douglashox said:
2019-10-14 03:00:02

"business"

canadianpharmacyndamus said:
2019-10-14 11:42:47

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

canadianpharmacyndamus said:
2019-10-14 12:20:19

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

Douglashox said:
2019-10-14 16:20:28

"company news"

canadianpharmacyndamus said:
2019-10-15 03:50:50

"canadian pharmacy viagra generic canadian pharmacy online online canadian pharmacy canadian pharmacy generic viagra online canadian pharmacy viagra online canadian pharmacy online pharmacy canada generic viagra online canadian pharmacy"

Douglashox said:
2019-10-15 06:36:57

"company news"

canadianpharmacyndamus said:
2019-10-15 16:49:40

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

canadianpharmacyndamus said:
2019-10-16 09:14:57

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

canadianpharmacyndamus said:
2019-10-16 22:00:54

"canadian drugs cheap viagra online canadian pharmacy online canadian pharmacy canadian pharmacy generic viagra canadian pharmacy generic viagra canadian pharmacy online generic viagra from canada canadian pharmacy online"

canadianpharmacyndamus said:
2019-10-16 22:39:10

"canadian pharmacy online viagra online canadian pharmacy canadian drug stores canadian pharmacy online canadian generic viagra viagra online canadian pharmacy canadian drugs generic viagra online canadian pharmacy"

Cindycbaceva said:
2019-10-17 20:42:59

"cialis online tadalafil citrate cialis 10 mg"

Cindynhaceva said:
2019-10-18 00:08:31

"cialis vs viagra tadalafil cialis cialis for bph"

canadianpharmacyndamus said:
2019-10-18 00:56:49

"generic viagra from canada canadian pharmacy online generic canadian viagra canadian pharmacy generic viagra canada pharmacy online canadian pharmacy generic viagra canadian pharmacy meds canadian pharmacy generic viagra"

Cindyroaceva said:
2019-10-18 04:37:44

"cialis for sale sildenafil without a doctor's prescription cialis for men"

Cindyeqaceva said:
2019-10-18 09:50:32

"buy generic cialis ed pills online order cialis online"

Cindyxvaceva said:
2019-10-18 14:49:44

"cialis coupon buy generic ed pills online buy cialis"

Cindyunaceva said:
2019-10-18 21:50:43

"cialis 20 mg canadian pharmacy meds cialis coupons"

Cindyqlaceva said:
2019-10-19 05:01:50

"cialis without prescription nexium tablets cialis super active"

Cindyxcaceva said:
2019-10-19 11:42:26

"cialis online generic cialis tadalafil uk cialis cost"

Cindyhoaceva said:
2019-10-19 18:51:52

"buy cialis online viagra without prescription cialis coupon"

Cindyfxaceva said:
2019-10-20 05:12:21

"generic cialis online generic cialis tadalafil uk cheap cialis online"

canadianpharmacyndamus said:
2019-10-20 07:32:59

"generic viagra online canada canadian pharmacy online generic canadian viagra canadian pharmacy generic viagra canadian pharmacies online viagra online canadian pharmacy canadian pharmacy viagra generic canadian pharmacy generic viagra"

canadianpharmacyndamus said:
2019-10-20 10:17:08

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

Charlestit said:
2019-10-20 13:56:15

"cheap vardenafil cafergot 1/100 "

Charlestit said:
2019-10-21 04:59:28

"cheap erection pills generic and brand name of metformin "

uguqowuri said:
2019-10-21 05:15:56

"http://mewkid.net/buy-relomber/ - Cialis Generic Cialis tdi.zixp.eclairbytes.com.adu.ta http://mewkid.net/buy-relomber/"


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! :)

(SHOW ALL COMMENTS)

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: https://www.good-webhosting.com/"