Resistor Color Code Decoder
Decode resistor values from color bands. Standard electronics tool for reading resistor values. 4-band, 5-band, and 6-band resistors. Essential for circuit design and troubleshooting.
Visualization
Interactive visualization for Resistor Color Code Decoder
1000 Ω
Resistor Color Code:
- • Read resistance from color bands
- • Band1,Band2,Multiplier
Interactive visualization with step-by-step execution
Implementation
1class ResistorColorCode {
2 private colorDigits: { [key: string]: number } = {
3 'black': 0, 'brown': 1, 'red': 2, 'orange': 3, 'yellow': 4,
4 'green': 5, 'blue': 6, 'violet': 7, 'grey': 8, 'white': 9
5 };
6
7 private multipliers: { [key: string]: number } = {
8 'black': 1, 'brown': 10, 'red': 100, 'orange': 1000,
9 'yellow': 10000, 'green': 100000, 'blue': 1000000,
10 'violet': 10000000, 'grey': 100000000, 'white': 1000000000,
11 'gold': 0.1, 'silver': 0.01
12 };
13
14 private tolerances: { [key: string]: number } = {
15 'brown': 1, 'red': 2, 'green': 0.5, 'blue': 0.25,
16 'violet': 0.1, 'grey': 0.05, 'gold': 5, 'silver': 10
17 };
18
19 decode4Band(bands: string[]): { value: number; tolerance: number; formatted: string } {
20 const digit1 = this.colorDigits[bands[0].toLowerCase()];
21 const digit2 = this.colorDigits[bands[1].toLowerCase()];
22 const multiplier = this.multipliers[bands[2].toLowerCase()];
23 const tolerance = this.tolerances[bands[3].toLowerCase()];
24
25 const value = (digit1 * 10 + digit2) * multiplier;
26
27 return {
28 value,
29 tolerance,
30 formatted: this.formatResistance(value, tolerance)
31 };
32 }
33
34 decode5Band(bands: string[]): { value: number; tolerance: number; formatted: string } {
35 const digit1 = this.colorDigits[bands[0].toLowerCase()];
36 const digit2 = this.colorDigits[bands[1].toLowerCase()];
37 const digit3 = this.colorDigits[bands[2].toLowerCase()];
38 const multiplier = this.multipliers[bands[3].toLowerCase()];
39 const tolerance = this.tolerances[bands[4].toLowerCase()];
40
41 const value = (digit1 * 100 + digit2 * 10 + digit3) * multiplier;
42
43 return {
44 value,
45 tolerance,
46 formatted: this.formatResistance(value, tolerance)
47 };
48 }
49
50 private formatResistance(value: number, tolerance: number): string {
51 if (value >= 1000000) {
52 return `${value / 1000000}MΩ ±${tolerance}%`;
53 } else if (value >= 1000) {
54 return `${value / 1000}kΩ ±${tolerance}%`;
55 } else {
56 return `${value}Ω ±${tolerance}%`;
57 }
58 }
59}Deep Dive
Theoretical Foundation
Color bands represent digits and multipliers. Band 1&2 (or 1-3): significant digits. Next: multiplier (10^n). Last: tolerance (±%). 4-band: 2 digits + multiplier + tolerance. 5-band: 3 digits + multiplier + tolerance. 6-band adds temperature coefficient.
Complexity
Time
O(1)
O(1)
O(1)
Space
O(1)
Applications
Industry Use
Electronics manufacturing and assembly
Circuit board design and prototyping
Electronics repair and troubleshooting
Educational electronics courses
Quality control in component inspection
Inventory management in electronics stores
Hobbyist electronics projects
Use Cases
Related Algorithms
GCD (Euclidean Algorithm)
Compute the Greatest Common Divisor (GCD) of two integers using the Euclidean algorithm. Dating back to around 300 BC and appearing in Euclid's Elements, it's one of the oldest algorithms still in common use. The algorithm is based on the principle that GCD(a,b) = GCD(b, a mod b) and is remarkably efficient with O(log min(a,b)) time complexity. The GCD is the largest positive integer that divides both numbers without remainder.
LCM (Least Common Multiple)
Calculate the Least Common Multiple (LCM) of two integers - the smallest positive integer that is divisible by both numbers. The LCM is intimately related to the GCD through the formula: LCM(a,b) = |a×b| / GCD(a,b). This relationship allows us to compute LCM efficiently using the Euclidean algorithm for GCD, achieving O(log min(a,b)) time complexity instead of naive factorization methods.
Sieve of Eratosthenes
Ancient and highly efficient algorithm to find all prime numbers up to a given limit n. Invented by Greek mathematician Eratosthenes of Cyrene (276-194 BC), this sieve method systematically eliminates multiples of primes, leaving only primes in the array. With O(n log log n) time complexity, it remains one of the most practical algorithms for generating large lists of primes, vastly superior to trial division which runs in O(n² / log n) time.
Prime Factorization
Decompose a positive integer into its unique prime factor representation. Every integer greater than 1 can be expressed as a product of prime numbers in exactly one way (Fundamental Theorem of Arithmetic). This algorithm uses trial division optimized to check only up to √n, as any composite number must have a prime factor ≤ √n. Returns a map of prime factors to their powers, e.g., 360 = 2³ × 3² × 5¹.