Color Code of Resistor

Hey, guys!

I created a resistor program that calculates resistance from colors, but I’m not sure how to convert resistance to color. Can you assist me with putting this together?

For example, if I enter 100 ohms and a 5% tolerance, the hues brown, black, brown, and gold appear.

We need more information. Like, is this some kind of Fritzing plugin? What programming language are you writting in, etc, ect. Please be more specific.

A quick explaination is that you can use arrays and link same indexes of arrays, for example resistance XX is “resistanse_array [5]” that links to color XX which is “color_array [5]”.

That is correct. The resistance is 100 ohms. Brown (1) black. (0) followed by 1 zero to give 100 (1K would be brown black red to indicate 2 trailing zeros or 1000 ohms) and the gold indicates 5% tolerance.


One method, basic concept, is to convert the resistance value to a string in Ohms, then lookup the color code for each of the first 2 or 3 digits (depending whether you want a 4 or 5 band color code), then count the number of digits left over, and convert that to the multiplier band color. Finally add the color for the tolerance. For small value resistors, the “count” could be negative, which is where the silver and gold multiplier bands come from.

There are cleaner ways to get the same result, but that will work.

This tool might do you a favor.

That tools does exactly what the OP said his code already did. What he asked about was how to do the reverse case. And another tool that just does the job would not be an answer either. Unless the code for it was publicly available. What was asked for, was how to get the code to do it (the reverse case).