2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

8桁バーコードのチェックデジット

Last updated at Posted at 2015-06-25

チェックデジット計算方式

modulus10, weight3

excel

Numbers でも動作

=RIGHT(
    10-RIGHT(
        SUM(
            SUM(
                MID(A1,1,1),
                MID(A1,3,1),
                MID(A1,5,1),
                MID(A1,7,1)
            )*3,
            SUM(
                MID(A1,2,1),
                MID(A1,4,1),
                MID(A1,6,1)
            )
        )
        ,1
    )
)

A1 はセル位置。

perl

my @d = split //, BARCODE_DATA ;
sub ad{ eval join q{+}, @_ } ; 
my $che = ( (  10 - ( ( ad @d[0,2,4,6] ) * 3 + ad @d[1,3,5]  ) % 10 ) % 10 )  ;
die if $che != $d[-1] ;

BARCODE_DATA はもちろん、対応するバーコード文字列

20151027 追記

結局マクロを触らなきゃならんくなった、、、

VBA

Function digit8(Byval d As String)
    Dim o As Integer
    Dim i As Integer
    
    For i = 1 To 7 Step 2
        o = o + CLng(Mid(d, i, 1))
    Next
    o = o * 3
    
    For i = 2 To 6 Step 2
        o = o + CLng(Mid(d, i, 1))
    Next
    o = (10 - (o Mod 10)) Mod 10
    
    digit8 = o
    
End Function

適当なセルにて =digit8(A1) とかする、、、

ruby

$ ruby -e 'd = "9876543".split("").map(&:to_i) ;  p  ( 10 - (d.values_at(0,2,4,6).inject(:+) * 3 + d.values_at(1,3,5).inject(:+) ) % 10 ) % 10 '
0
2
3
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?