void intToBytesLittle(int value, unsigned char*cSendBuff,int pos) {
cSendBuff[pos+3] = (byte)((value >> 24) & 0xFF);
cSendBuff[pos+2] = (byte)((value >> 16) & 0xFF);
cSendBuff[pos+1] = (byte)((value >> 8) & 0xFF);
cSendBuff[pos+0] = (byte)(value & 0xFF);
}
void BigintToBytesLittle(unsigned long long value, unsigned char*cSendBuff, int pos) {
cSendBuff[pos + 7] = (byte)((value >> 56) & 0xFF);
cSendBuff[pos + 6] = (byte)((value >> 48) & 0xFF);
cSendBuff[pos + 5] = (byte)((value >> 40) & 0xFF);
cSendBuff[pos + 4] = (byte)((value >> 32) & 0xFF);
cSendBuff[pos + 3] = (byte)((value >> 24) & 0xFF);
cSendBuff[pos + 2] = (byte)((value >> 16) & 0xFF);
cSendBuff[pos + 1] = (byte)((value >> 8) & 0xFF);
cSendBuff[pos + 0] = (byte)(value & 0xFF);
}
void shotIntToBytesLittle(short int value, unsigned char*cSendBuff, int pos) {
cSendBuff[pos + 1] = (byte)((value >> 8) & 0xFF);
cSendBuff[pos + 0] = (byte)(value & 0xFF);
}
void floatToBytesLittle(float value, unsigned char*cSendBuff, int pos)
{
unsigned short i = 0;
float floatVariable = value;
unsigned char *pdata = (unsigned char *)&floatVariable;
for (i = 0; i < 4; i++)
{
cSendBuff[i+pos] = *pdata++;//float转BYTE
}
}
unsigned int FloatToUInt32(float value)
{
return (unsigned int)(&value);
}
float UInt32ToFloat(unsigned int value)
{
return (float)(&value);
}
unsigned long long DoubleToBigUInt32(double value)
{
return (unsigned long long)(&value);
}
double BigUInt32ToDouble(unsigned long long value)
{
return (double)(&value);
}