#include <iostream>
using namespace std;
int main() {
private string EpcEncoding(string sku, string sn)
{
if (string.IsNullOrEmpty(sku))
{
cc.MsgBox("请填写SKU");
return string.Empty;
}
if (sku.Length != 13)
{
cc.MsgBox("SKU长度错误,应该为13位");
return string.Empty;
}
if (!char.IsDigit(sku[0]))
{
cc.MsgBox("SKU的第一个字符必须为数字");
return string.Empty;
}
if (string.IsNullOrEmpty(sn) || sn.Length != 5)
{
cc.MsgBox("SN错误");
return string.Empty;
}
char yearCode = sku[1];
if (yearCode < 'A' || yearCode > 'Z')
{
cc.MsgBox("SKU年份码错误");
return string.Empty;
}
int year = yearCode - 'M' + 23;
string sku2 = sku.Substring(0, 1) + year.ToString() + sku.Substring(2);
if (!long.TryParse(sku2, out long skuLong))
{
cc.MsgBox("SKU转换失败,包含无效字符");
return string.Empty;
}
BigInteger skuI = (BigInteger)skuLong << 34;
BigInteger header = (BigInteger)0x3138 << 80;
if (!long.TryParse(sn, out long snLong))
{
cc.MsgBox("SN必须为数字");
return string.Empty;
}
BigInteger snI = (BigInteger)snLong;
BigInteger value = header + skuI + snI;
byte[] epc = value.ToByteArray();
List<byte> epcList = new List<byte>(epc);
if (epcList.Count > 0 && epcList.Last() == 0)
epcList.RemoveAt(epcList.Count - 1);
int desiredLength = 12;
if (epcList.Count > desiredLength)
{
epcList = epcList.GetRange(epcList.Count - desiredLength, desiredLength);
}
else if (epcList.Count < desiredLength)
{
epcList.InsertRange(0, Enumerable.Repeat((byte)0, desiredLength - epcList.Count));
}
byte[] epcReverse = new byte[desiredLength];
for (int i = 0; i < desiredLength; i++)
epcReverse[i] = epcList[desiredLength - 1 - i];
return cc.BinToStringSimple(epcReverse);
}
cout << "Hello world! - cpp.jsrun.net." << endl;
return 0;
}