General > General Technical Chat
Small and stupid decoder for EIA96 resistor markings
(1/2) > >>
magic:
I was getting tired of using tables to decode those resistors, so I wrote a Perl script which takes the 3-symbol code and spits out its corresponding resistance value. It is probably mainly of interest to Linux users, because you just put it in your ~/bin and call it from terminal like any other program, but nothing stops one from porting the algorithm to some other language and/or platform. I verified one full decade of its output against this table. If somebody knows a more authoritative source, I will re-check.


--- Code: ---$ eia96 01b
1000
--- End code ---

You can even call it with an incorrect code or no argument at all and it will print some nonsense.

--- Code: ---$ eia96 hello
98
--- End code ---

Full code below. Straightforward stuff. The int(xxx + 0.5) part is rounding to nearest integer.

--- Code: ---#!/usr/bin/perl -l

my $d = substr($ARGV[0], 0, 2);
my $e = lc(substr($ARGV[0], -1));

my $v = int(100 * 10**(($d-1)/96) + 0.5);

$v *= 0.001 if $e eq "z";
$v *= 0.01 if $e eq "y" || $e eq "r";
$v *= 0.1 if $e eq "x" || $e eq "s";
$v *= 1 if $e eq "a";
$v *= 10 if $e eq "b" || $e eq "h";
$v *= 100 if $e eq "c";
$v *= 1000 if $e eq "d";
$v *= 10000 if $e eq "e";
$v *= 100000 if $e eq "f";

print $v;
--- End code ---
BeBuLamar:
You can read the resistor values without anything now?
Benta:
Nice idea.
Downside is that it doesn't solve the problem of undecipherable colours on modern resistors, where blue/green or red/brown are indistinguishable from each other.
notsob:
just put electrodoc on your smartphone
ledtester:

--- Quote from: magic on March 01, 2022, 10:59:04 am ---

--- Code: ---#!/usr/bin/perl -l
...

--- End code ---

--- End quote ---

It's nice to see a perl program these days!
Navigation
Message Index
Next page
There was an error while thanking
Thanking...

Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod