Skip to content

Commit

Permalink
fix single digit Pharmacode
Browse files Browse the repository at this point in the history
  • Loading branch information
barnhill committed Feb 23, 2020
1 parent 159301d commit 0df2f07
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
4 changes: 2 additions & 2 deletions BarcodeStandard/BarcodeStandard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>2.2.3</Version>
<Version>2.2.4</Version>
<PackageId>BarcodeLib</PackageId>
<Company>Pnuema Productions</Company>
<Product>BarcodeLib</Product>
<Authors>Brad Barnhill</Authors>
<Description>This library was designed to give an easy class for developers to use when they need to generate barcode images from a string of data.</Description>
<Copyright>Copyright 2007-2019 Brad Barnhill</Copyright>
<Copyright>Copyright 2007-2020 Brad Barnhill</Copyright>
<PackageLicenseUrl></PackageLicenseUrl>
<PackageProjectUrl>https://github.com/barnhill/barcodelib</PackageProjectUrl>
<PackageIconUrl>https://github.com/barnhill/barcodelib/master/BarcodeStandard/examples/upca.gif</PackageIconUrl>
Expand Down
2 changes: 2 additions & 0 deletions BarcodeStandard/Release Notes.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Release Notes for BarcodeLib.dll
================================
2.2.4.0
- Fix incorrect encoding for single digit Pharmacode
2.2.3.0
- Allow use in partially trusted assemblies for SSRS
2.2.2.0
Expand Down
30 changes: 10 additions & 20 deletions BarcodeStandard/Symbologies/Pharmacode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,35 +58,25 @@ private string Encode_Pharmacode()
}
}

double sum = Math.Pow(2, startIndex + 1) - 2;
string [] encoded = new string[startIndex + 1];
int i = 0;

for (int index = startIndex; index >= 0; index--)
string result = String.Empty;
do
{
double power = Math.Pow(2, index);
double diff = num - sum;
if (diff > power)
if ((num & 1) == 0)
{
encoded[i++] = _thickBar;
sum += power;
result = _thickBar + result;
num = (num - 2) / 2;
}
else
{
encoded[i++] = _thinBar;
result = _thinBar + result;
num = (num - 1) / 2;
}
}

string result = String.Empty;
foreach (string s in encoded)
{
if (result != String.Empty)
if (num != 0)
{
result += _gap;
result = _gap + result;
}

result += s;
}
} while (num != 0);

return result;
}
Expand Down

0 comments on commit 0df2f07

Please sign in to comment.