永发信息网

求达人将此段C#代码转化成C语言

答案:2  悬赏:30  手机版
解决时间 2021-05-17 11:03

代码如下..

C不是很懂,写起来很多错,不得以才求助,大家帮帮忙啊

static void Main(string[] args)
{
byte[] data = { 0x52, 0x52, 0x52, Convert.ToByte("1") };
byte[] sendorder = new byte[data.Length + 13];
byte[] temp=GetCRC(data);
Console.WriteLine(Convert.ToString(temp[0], 0x10).PadLeft(2, '0').PadRight(3, ' ').ToUpper());
Console.WriteLine(Convert.ToString(temp[1], 0x10).PadLeft(2, '0').PadRight(3, ' ').ToUpper());

}
private static byte[] ha00 =
{
0x00,0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x81,0x91,0xA1,0xB1,0xC1,0xD1,0xE1,0xF1,
0x12,0x02,0x32,0x22,0x52,0x42,0x72,0x62,0x93,0x83,0xB3,0xA3,0xD3,0xC3,0xF3,0xE3,
0x24,0x34,0x04,0x14,0x64,0x74,0x44,0x54,0xA5,0xB5,0x85,0x95,0xE5,0xF5,0xC5,0xD5,
0x36,0x26,0x16,0x06,0x76,0x66,0x56,0x46,0xB7,0xA7,0x97,0x87,0xF7,0xE7,0xD7,0xC7,
0x48,0x58,0x68,0x78,0x08,0x18,0x28,0x38,0xC9,0xD9,0xE9,0xF9,0x89,0x99,0xA9,0xB9,
0x5A,0x4A,0x7A,0x6A,0x1A,0x0A,0x3A,0x2A,0xDB,0xCB,0xFB,0xEB,0x9B,0x8B,0xBB,0xAB,
0x6C,0x7C,0x4C,0x5C,0x2C,0x3C,0x0C,0x1C,0xED,0xFD,0xCD,0xDD,0xAD,0xBD,0x8D,0x9D,
0x7E,0x6E,0x5E,0x4E,0x3E,0x2E,0x1E,0x0E,0xFF,0xEF,0xDF,0xCF,0xBF,0xAF,0x9F,0x8F,
0x91,0x81,0xB1,0xA1,0xD1,0xC1,0xF1,0xE1,0x10,0x00,0x30,0x20,0x50,0x40,0x70,0x60,
0x83,0x93,0xA3,0xB3,0xC3,0xD3,0xE3,0xF3,0x02,0x12,0x22,0x32,0x42,0x52,0x62,0x72,
0xB5,0xA5,0x95,0x85,0xF5,0xE5,0xD5,0xC5,0x34,0x24,0x14,0x04,0x74,0x64,0x54,0x44,
0xA7,0xB7,0x87,0x97,0xE7,0xF7,0xC7,0xD7,0x26,0x36,0x06,0x16,0x66,0x76,0x46,0x56,
0xD9,0xC9,0xF9,0xE9,0x99,0x89,0xB9,0xA9,0x58,0x48,0x78,0x68,0x18,0x08,0x38,0x28,
0xCB,0xDB,0xEB,0xFB,0x8B,0x9B,0xAB,0xBB,0x4A,0x5A,0x6A,0x7A,0x0A,0x1A,0x2A,0x3A,
0xFD,0xED,0xDD,0xCD,0xBD,0xAD,0x9D,0x8D,0x7C,0x6C,0x5C,0x4C,0x3C,0x2C,0x1C,0x0C,
0xEF,0xFF,0xCF,0xDF,0xAF,0xBF,0x8F,0x9F,0x6E,0x7E,0x4E,0x5E,0x2E,0x3E,0x0E,0x1E

};
private static byte[] la00 =
{
0x00,0x21,0x42,0x63,0x84,0xA5,0xC6,0xE7,0x08,0x29,0x4A,0x6B,0x8C,0xAD,0xCE,0xEF,
0x31,0x10,0x73,0x52,0xB5,0x94,0xF7,0xD6,0x39,0x18,0x7B,0x5A,0xBD,0x9C,0xFF,0xDE,
0x62,0x43,0x20,0x01,0xE6,0xC7,0xA4,0x85,0x6A,0x4B,0x28,0x09,0xEE,0xCF,0xAC,0x8D,
0x53,0x72,0x11,0x30,0xD7,0xF6,0x95,0xB4,0x5B,0x7A,0x19,0x38,0xDF,0xFE,0x9D,0xBC,
0xC4,0xE5,0x86,0xA7,0x40,0x61,0x02,0x23,0xCC,0xED,0x8E,0xAF,0x48,0x69,0x0A,0x2B,
0xF5,0xD4,0xB7,0x96,0x71,0x50,0x33,0x12,0xFD,0xDC,0xBF,0x9E,0x79,0x58,0x3B,0x1A,
0xA6,0x87,0xE4,0xC5,0x22,0x03,0x60,0x41,0xAE,0x8F,0xEC,0xCD,0x2A,0x0B,0x68,0x49,
0x97,0xB6,0xD5,0xF4,0x13,0x32,0x51,0x70,0x9F,0xBE,0xDD,0xFC,0x1B,0x3A,0x59,0x78,
0x88,0xA9,0xCA,0xEB,0x0C,0x2D,0x4E,0x6F,0x80,0xA1,0xC2,0xE3,0x04,0x25,0x46,0x67,
0xB9,0x98,0xFB,0xDA,0x3D,0x1C,0x7F,0x5E,0xB1,0x90,0xF3,0xD2,0x35,0x14,0x77,0x56,
0xEA,0xCB,0xA8,0x89,0x6E,0x4F,0x2C,0x0D,0xE2,0xC3,0xA0,0x81,0x66,0x47,0x24,0x05,
0xDB,0xFA,0x99,0xB8,0x5F,0x7E,0x1D,0x3C,0xD3,0xF2,0x91,0xB0,0x57,0x76,0x15,0x34,
0x4C,0x6D,0x0E,0x2F,0xC8,0xE9,0x8A,0xAB,0x44,0x65,0x06,0x27,0xC0,0xE1,0x82,0xA3,
0x7D,0x5C,0x3F,0x1E,0xF9,0xD8,0xBB,0x9A,0x75,0x54,0x37,0x16,0xF1,0xD0,0xB3,0x92,
0x2E,0x0F,0x6C,0x4D,0xAA,0x8B,0xE8,0xC9,0x26,0x07,0x64,0x45,0xA2,0x83,0xE0,0xC1,
0x1F,0x3E,0x5D,0x7C,0x9B,0xBA,0xD9,0xF8,0x17,0x36,0x55,0x74,0x93,0xB2,0xD1,0xF0
};
private static void CRCXor(ref byte a, ref byte b, ref byte c)
{
c = Convert.ToByte(la00[a] ^ c);
a = Convert.ToByte(ha00[a] ^ b);
b = c;
}
public static byte[] GetCRC(byte[] s)
{
byte[] crc = new byte[2];
byte a = s[0];
byte b = s[1];
byte c = s[2];
CRCXor(ref a, ref b, ref c);
for (int i = 3; i <= s.Length - 1; i++)
{
c = s[i];
CRCXor(ref a, ref b, ref c);
}
crc[0] = a;
crc[1] = b;
return crc;
}
}

最佳答案

char ha00[] =
{
0x00,0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x81,0x91,0xA1,0xB1,0xC1,0xD1,0xE1,0xF1,
0x12,0x02,0x32,0x22,0x52,0x42,0x72,0x62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,0xC0,0xE1,0x82,0xA3,
0x7D,0x5C,0x3F,0x1E,0xF9,0xD8,0xBB,0x9A,0x75,0x54,0x37,0x16,0xF1,0xD0,0xB3,0x92,
0x2E,0x0F,0x6C,0x4D,0xAA,0x8B,0xE8,0xC9,0x26,0x07,0x64,0x45,0xA2,0x83,0xE0,0xC1,
0x1F,0x3E,0x5D,0x7C,0x9B,0xBA,0xD9,0xF8,0x17,0x36,0x55,0x74,0x93,0xB2,0xD1,0xF0
};
void CRCXor(char &a, char &b, char &c)
{
*c = (char)(la00[*a] ^ *c);
*a = (char)(ha00[*a] ^ *b);
*b = *c;
}
char * GetCRC(char s[])
{
int i;
char crc[2];
char a = s[0];
char b = s[1];
char c = s[2];
CRCXor(&a, &b, &c);
for (i = 3; i <= strlen(s)-1; i++)
{
c = s[i];
CRCXor(&a, &b, &c);
}
crc[0] = a;
crc[1] = b;
return crc;
}



static void Main()
{
char data[] = { 0x52, 0x52, 0x52, char('1') };
char sendorder[4];
char temp[] =GetCRC(data);
}



最后两句话用C很难实现,看不懂,是干什么的呀

全部回答

#include<stdio.h> #include<string.h>

char ha00[] = { 0x00,0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x81,0x91,0xA1,0xB1,0xC1,0xD1,0xE1,0xF1, 0x12,0x02,0x32,0x22,0x52,0x42,0x72,0x62,0x93,0x83,0xB3,0xA3,0xD3,0xC3,0xF3,0xE3, 0x24,0x34,0x04,0x14,0x64,0x74,0x44,0x54,0xA5,0xB5,0x85,0x95,0xE5,0xF5,0xC5,0xD5, 0x36,0x26,0x16,0x06,0x76,0x66,0x56,0x46,0xB7,0xA7,0x97,0x87,0xF7,0xE7,0xD7,0xC7, 0x48,0x58,0x68,0x78,0x08,0x18,0x28,0x38,0xC9,0xD9,0xE9,0xF9,0x89,0x99,0xA9,0xB9, 0x5A,0x4A,0x7A,0x6A,0x1A,0x0A,0x3A,0x2A,0xDB,0xCB,0xFB,0xEB,0x9B,0x8B,0xBB,0xAB, 0x6C,0x7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A,0x19,0x38,0xDF,0xFE,0x9D,0xBC, 0xC4,0xE5,0x86,0xA7,0x40,0x61,0x02,0x23,0xCC,0xED,0x8E,0xAF,0x48,0x69,0x0A,0x2B, 0xF5,0xD4,0xB7,0x96,0x71,0x50,0x33,0x12,0xFD,0xDC,0xBF,0x9E,0x79,0x58,0x3B,0x1A, 0xA6,0x87,0xE4,0xC5,0x22,0x03,0x60,0x41,0xAE,0x8F,0xEC,0xCD,0x2A,0x0B,0x68,0x49, 0x97,0xB6,0xD5,0xF4,0x13,0x32,0x51,0x70,0x9F,0xBE,0xDD,0xFC,0x1B,0x3A,0x59,0x78, 0x88,0xA9,0xCA,0xEB,0x0C,0x2D,0x4E,0x6F,0x80,0xA1,0xC2,0xE3,0x04,0x25,0x46,0x67, 0xB9,0x98,0xFB,0xDA,0x3D,0x1C,0x7F,0x5E,0xB1,0x90,0xF3,0xD2,0x35,0x14,0x77,0x56, 0xEA,0xCB,0xA8,0x89,0x6E,0x4F,0x2C,0x0D,0xE2,0xC3,0xA0,0x81,0x66,0x47,0x24,0x05, 0xDB,0xFA,0x99,0xB8,0x5F,0x7E,0x1D,0x3C,0xD3,0xF2,0x91,0xB0,0x57,0x76,0x15,0x34, 0x4C,0x6D,0x0E,0x2F,0xC8,0xE9,0x8A,0xAB,0x44,0x65,0x06,0x27,0xC0,0xE1,0x82,0xA3, 0x7D,0x5C,0x3F,0x1E,0xF9,0xD8,0xBB,0x9A,0x75,0x54,0x37,0x16,0xF1,0xD0,0xB3,0x92, 0x2E,0x0F,0x6C,0x4D,0xAA,0x8B,0xE8,0xC9,0x26,0x07,0x64,0x45,0xA2,0x83,0xE0,0xC1, 0x1F,0x3E,0x5D,0x7C,0x9B,0xBA,0xD9,0xF8,0x17,0x36,0x55,0x74,0x93,0xB2,0xD1,0xF0 }; void CRCXor(char *a, char *b, char *c) { *c = (char)(la00[*a] ^ *c); *a = (char)(ha00[*a] ^ *b); *b = *c; } void GetCRC(char s[],char crc[]) { int i; char a = s[0]; char b = s[1]; char c = s[2]; CRCXor(&a, &b, &c); for (i = 3; i <= strlen(s)-1; i++) { c = s[i]; CRCXor(&a, &b, &c); } crc[0] = a; crc[1] = b; }

void main() { char data[] = { 0x52, 0x52, 0x52, char('1') }; char sendorder[4]; char temp[2]; GetCRC(data,temp); printf("%p\n",temp[0]); printf("%p\n",temp[1]);

}

我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
双子座好不好
解放区焦作百货大楼(西城美苑店)在什么地方啊
蓄电激光炮最高加到几?怎么加?
松江博大医院割包皮多少
台州现在穿什么衣服啊?冷吗?
QQ飞车中的蛋现在怎么得啊
只要是工作就签劳动合同吗?
我想问一下,学习java就业的话都需要哪些认证
用手机充币
宜都市宜昌中国福利彩票哪位知道具体地址啊
excel数据透视表怎么快速统计统计重复次数
急求一篇商业方面的英语演讲稿,700~800词的
请问一个wow的问题
我的手机是NOKIA5130的,才买1个月,就白屏自
起什麼情侶名最拽
推荐资讯
QCC的后台怎样进入?
遂平县驻马店蜜雪冰城(遂平奥利匹克广场店)地
方城县南阳张东方牙科地址在什么地方,想今天
不倒翁掉水里歇后语,请问第一个盐店老板,猜
七雄争霸 一级进阶英雄但颜色不变
游戏一进去不过1分钟就跳了,说有非法模块,
小狗生病了,不知怎么拯救它?
人活着为什么会那么烦?怎么样做才能让自己过
准备给母亲迁坟要看日子,有谁能看一下日子,
以后我们死了那QQ号怎么办呢?
WOW里的LM怎么和BL交易啊?
岳麓区长沙情怀story主题公寓这个地址怎么能
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?