Cunsigned time6le_2sec(char *buff){unsigned h;unsigned l=0;unsigned sech;unsigned secl; (char*)(&h)[3]=buff[0];(char*)(&h)[2]=buff[1];(char*)(&h)[1]=buff[2];(char*)(&h)[0]=buff[3];sech = h / 1000;l = (h % 1000) << 16 + buff[4] << 8 + buff[5];secl = l / 1000;return secl + sech << 16;}
C++ (Qt)unsigned char buf [6]; double r = 0;for (int i = 0; i < 6; ++i) r = r * 256 + buf [i]; std::cout << (unsigned) (r / 1000) << std::endl;
Cvoid div_1000_abs_time(u8 *t){ double sec = t[0]; sec = (sec * 256) + t[1]; sec = (sec * 256) + t[2]; sec = (sec * 256) + t[3]; sec = (sec * 256) + t[4]; sec = (sec * 256) + t[5]; sec /= 1000; u32 r = u32(sec); t[0] = 0x00; t[1] = 0x00; t[2] = r >> 24; t[3] = r >> 16; t[4] = r >> 8; t[5] = r;}
Cvoid div_1000_abs_time2(u8 *t){ u32 h; ((u8 *)(&h))[3] = t[0]; ((u8 *)(&h))[2] = t[1]; ((u8 *)(&h))[1] = t[2]; ((u8 *)(&h))[0] = t[3]; u32 sech = h / 1000; u32 secl = (h % 1000); secl <<= 16; secl += (t[4] << 8) + t[5]; secl /= 1000; secl += (sech << 16); t[0] = 0x00; t[1] = 0x00; t[2] = secl >> 24; t[3] = secl >> 16; t[4] = secl >> 8; t[5] = secl;}
Ctypedef unsigned char u8;typedef unsigned short u16;typedef unsigned long u32;
C++ (Qt)unsigned d1000 (unsigned char *buf){ unsigned result = 0, carry = 0, d = 1000, char_bit = 8; for (int i = 0; i < 6; ++i, carry <<= char_bit) { unsigned u = buf [i] + carry; result = (result << char_bit) + u / d; carry = u % d; } return result;}
C...#include <limits.h>......void div_1000_abs_time3(u8 *t){ enum { D = 1000 }; u32 u = t[0]; u32 result = (u / D); u32 carry = (u % D) << CHAR_BIT; u = t[1] + carry; result = (result << CHAR_BIT) + (u / D); carry = (u % D) << CHAR_BIT; u = t[2] + carry; result = (result << CHAR_BIT) + (u / D); carry = (u % D) << CHAR_BIT; u = t[3] + carry; result = (result << CHAR_BIT) + (u / D); carry = (u % D) << CHAR_BIT; u = t[4] + carry; result = (result << CHAR_BIT) + (u / D); carry = (u % D) << CHAR_BIT; u = t[5] + carry; result = (result << CHAR_BIT) + (u / D); t[0] = 0x00; t[1] = 0x00; t[2] = result >> 24; t[3] = result >> 16; t[4] = result >> 8; t[5] = result;}