C# 產生UPC-A碼

來源:互聯網
上載者:User

標籤:

因為最近工作中用到UPC-A碼,所以就研究了下,先簡單介紹下UPC-A碼

UPC碼是美國統一代碼委員會制定的一種商品用條碼,主要用於美國和加拿大地區,我們在美國進口的商品上可以看到。UPC碼(Universal Product Code)是最早大規模應用的條碼,其特性是一種長度固定、連續性的條碼,目前主要在美國和加拿大使用,由於其應用範圍廣泛,故又被稱萬用條碼。 UPC碼僅可用來表示數字,故其字碼集為數字0~9。

主要格式如:


UPC-A

旗碼、廠商代碼、產品代碼需要跟相關部門申請,檢查碼是根據前面的代碼產生出來的,建置規則如下:

從國別碼開始自左至右取數,設UPC-A各碼代號如下:

N1N2N3N4N5N6N7N8N9N10N11C
則檢查碼之計算步驟如下:

C1 = N1+ N3+N5+N7+N9+N11

C2 = (N2+N4+N6+N8+N10)× 3

CC = (C1+C2) 取個位元

C (檢查碼) = 10 – CC  (若值為10,則取0)

 

 

C#產生檢查碼的代碼如下:

        //假設旗碼為7,廠商代碼為08502,傳入產品代碼即可產生出upc-a碼        private const string code = "708502";        public string GetCodeUPC(string number)        {            string strcode = code + number;            int c1 = int.Parse(strcode[10].ToString()) + int.Parse(strcode[8].ToString()) + int.Parse(strcode[6].ToString()) + int.Parse(strcode[4].ToString()) + int.Parse(strcode[2].ToString()) + int.Parse(strcode[0].ToString());            int c2 = c1 * 3;            int c3 = 0 + int.Parse(strcode[1].ToString()) + int.Parse(strcode[3].ToString()) + int.Parse(strcode[5].ToString()) + int.Parse(strcode[7].ToString()) + int.Parse(strcode[9].ToString());            int c4 = c2 + c3;            int c = 10 - c4 % 10;            if (c == 10) c = 0;            string upc = strcode + c.ToString();            return upc;        }

 

C# 產生UPC-A碼

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.