c ++ memcpy到Python memcpy [英] c++ memcpy To Python memcpy

查看:298
本文介绍了c ++ memcpy到Python memcpy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

c ++



c++

typedef unsigned char  U08;
typedef unsigned short U16;
typedef unsigned long  U32;

	U08 cpBuffer[] = {0x03, 0x06, 0x10, 0x02, 0x01, 0x01};	
	U32 BodyLength = 6;

	U16 CheckSum = 0x0000;
	U16 ZeroPadding = 0x0000;
	U16 Temp;
	U16 Test;

	if (!cpBuffer) 
		cout << "0" << endl;
	if (BodyLength < 1) 
		cout << "0" << endl;

	if((BodyLength % 2) != 0) 
	{
		ZeroPadding = (0x00FF & cpBuffer[BodyLength-1]);
		BodyLength--;
	}

	for (U32 i= 0; i < BodyLength; i+=2)
	{
		memcpy(&Temp, &cpBuffer[i], sizeof(U16));

		//cout << "index: " << i << endl;
		//cout << "cpBuffer: " << cpBuffer[i] << endl;
		cout << "Temp: " << Temp << endl;
		
		CheckSum += Temp;
		//cout << "checkSum: " << CheckSum << endl;
	}

	CheckSum += ZeroPadding;

	cout << "checkSum: " << CheckSum << endl;





========================= ================================================== =======



如何使用Python?



==================================================================================

How to Python?

推荐答案

请注意你不要在C ++和Python中都不需要 memcpy 来执行此类计算。

例如,请参阅Stack Overflow的问题:\"checksum udp calculation python [ ^ ]以深入了解如何使用普通的Python语言功能来计算校验和。
Please note you don't need memcpy, neither in C++ nor in Python, to perform such computations.
See, for instance, this Stack Overflow's question: "checksum udp calculation python"[^] to get some insight on how to use ordinary Python language features to compute checksums.


这篇关于c ++ memcpy到Python memcpy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆