Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
β’
248 items
β’
Updated
β’
1
BCD (Binary-Coded Decimal) single-digit adder as threshold circuit. Adds two decimal digits (0-9) with carry.
A[3:0] βββ (BCD digit 0-9)
B[3:0] βββΌβββΊ BCD Adder βββ¬βββΊ S[3:0] (BCD digit 0-9)
Cin βββ ββββΊ Cout (decimal carry)
1. Binary add: Z = A + B + Cin (4-bit result + carry)
2. Detect overflow: Z > 9 OR binary carry
3. If overflow: add 6 (0110) for correction
4. Decimal carry = overflow detected
BCD uses only values 0-9. When binary sum exceeds 9:
Adding 6 skips the invalid codes A-F (10-15).
| A | B | Cin | S | Cout |
|---|---|---|---|---|
| 5 | 3 | 0 | 8 | 0 |
| 5 | 5 | 0 | 0 | 1 |
| 9 | 9 | 0 | 8 | 1 |
| 9 | 9 | 1 | 9 | 1 |
| Stage | Component | Neurons |
|---|---|---|
| Binary add | 4 Full Adders | 28 |
| Detect >9 | AND, OR gates | 4 |
| Correction | 2 Half Adders + XOR | 11 |
Total: 43 neurons, 133 parameters, 5 layers
from safetensors.torch import load_file
w = load_file('model.safetensors')
# Valid inputs: A, B in range 0-9
# All 200 test cases verified (10 Γ 10 Γ 2)
threshold-bcd-adder/
βββ model.safetensors
βββ create_safetensors.py
βββ config.json
βββ README.md
MIT