🚀 From Random Bit-Flips to Error Detection: Building a Parity Checking Algorithm
Last time, we injected radiation-like errors into a tiny simulated computer and watched the program fall apart in real time. Today, we’re going one step further.
Instead of breaking the system… we’re going to teach it how to notice when something has gone wrong.
Welcome to the world of error-detecting codes — the first line of defense for spacecraft electronics.
🛰️ Why spacecraft need EDAC
In orbit, a single high-energy particle can flip a bit in RAM.
Just one wrong byte in a command, sensor reading, or pointer can turn a stable spacecraft into an unpredictable one. That’s why real flight computers constantly check their own memory, looking for silent corruption.
And the simplest technique of all is also one of the oldest:
#️⃣ Parity checking
🔍 Parity 101 — the simplest EDAC technique
Parity takes a group of bytes and computes a single value: their XOR.
Example:
Parity = D1 ⊕ D2 ⊕ D3 ⊕ D4
If any bit changes, the XOR result changes too. The system doesn’t know which byte flipped — but it knows something went wrong.
This makes parity perfect for teaching the fundamentals:
✔ Lightweight
✔ Fast
✔ Easy to implement
✔ Detects single-bit errors (and many multi-bit ones)
Some biliography:
🧩 A very simple parity example (bit-level)
Parity works even at the individual bit level. Here are two quick examples:
Example 1
Data: 1001100
Number of 1s: 3 (odd)
Parity bit: 1
Final byte: 1001100**1**
Example 2
Data: 1010011
Number of 1s: 4 (even)
Parity bit: 0
Final byte: 1010011**0**
🧩 Catching a flipped bit, an example:
Let’s say our program stores these four bytes in memory:
3C A5 18 F0
We compute their XOR parity:
3C ⊕ A5 ⊕ 18 ⊕ F0 = 71
Now imagine a high-energy particle flips a bit:
A5 → A1
Recompute:
3C ⊕ A1 ⊕ 18 ⊕ F0 = 75 (≠ 71)
👉 The system immediately detects the mismatch.
🧩 Why parity sometimes fails
If two flips happen in just the right pattern, the XOR may accidentally match the original:
A5 (1010 0101)
↓ flip bit 0
A4 (1010 0100)
18 (0001 1000)
↓ flip bit 3
10 (0001 0000)
Two flips — but the XOR remains unchanged.
This is less probable, but it can happen, and we will explore in the future.
🧪 Hands-on: Parity checking in Google Colab
I built a Colab notebook where you can:
✔ Load bytes into memory
✔ Compute their XOR parity
✔ Flip bits to simulate radiation
✔ Watch parity mismatch immediately detect corruption
👉 Try the Colab here:
https://colab.research.google.com/drive/1gaMz8WeNOXF_8VBhFHZWtf732HOutKrK?usp=sharing
It’s a clean, visual way to explore how radiation silently corrupts memory — and how parity reveals the problem.
🧭 Taking it to the microcontroller level
Now let’s move beyond Python and into assembly.
Inside our SMS32-like CPU simulator, I built a full Parity Checking example:
Stores
"Hello World!"in RAMComputes its XOR parity
Prints the string to video memory
Continuously recomputes parity
If any byte changes → jumps into
ERROR_LOOP
This mimics how embedded systems check their own memory in space: continuously and autonomously.
🔧 Try it yourself in the simulator
You can run this demo in the Zero2Orbit simulator:
👉 Open the Simulator:
https://www.zero2orbit.com/simulator
Then select the example:
Parity Bit Example (Parity Checking)
Steps:
Load the example
Press Run
Use the “Random Byte Flip” button
Watch the CPU immediately enter ERROR mode when a bit in
"Hello World!"flips
You’re seeing a real-time EDAC failure detection — exactly like in spacecraft electronics.
⏱️ Engineering tradeoffs: CPU time vs reliability
Before EDAC:
→ Print → Loop forever
With parity checking:
→ Calculate parity
→ Print
→ Check parity
→ Loop
It consumes extra CPU cycles. It adds latency, but it adds safety.
And that’s the tradeoff every space engineer knows:
Spend CPU time protecting memory, or risk silent corruption taking down your mission.
The right solution always depends on the system requirements.
🔜 What’s next?
Parity is only the beginning. It detects errors — but cannot correct them.
In the next article, we’ll explore Hamming Codes, a beautiful algorithm that can detect and correct single-bit errors automatically.
This is where things get really fun. ⚡🛰️