Help with ASCII conversion
-
I have a date time stamp which I have read from a file. I have read it as ascii characters and have stored it in a character array as follows: The data is stored in the reverse order in the file where I read it i.e. [0] [1] [2] [3] [4] [5] [6] [7] has to be reordered as [7] [6] [5] [4] [2] [1] [0]. The bytes are put into a character array as a hexadecimal representation of a timestamp. (actual example) dt = "0x01c5556a92792c8c0" Now in order to pass it to the localtime function I need to convert this ascii hex representation of my timestamp to an int64. I must be having a senior moment but I can't figure out how to do this (seemingly simple) operation. Could someone more experienced please help me with this? Thanks
-
I have a date time stamp which I have read from a file. I have read it as ascii characters and have stored it in a character array as follows: The data is stored in the reverse order in the file where I read it i.e. [0] [1] [2] [3] [4] [5] [6] [7] has to be reordered as [7] [6] [5] [4] [2] [1] [0]. The bytes are put into a character array as a hexadecimal representation of a timestamp. (actual example) dt = "0x01c5556a92792c8c0" Now in order to pass it to the localtime function I need to convert this ascii hex representation of my timestamp to an int64. I must be having a senior moment but I can't figure out how to do this (seemingly simple) operation. Could someone more experienced please help me with this? Thanks
Maybe not the shortest way, but should work:
__int64 test;
char buf[128];
const char dt[] = "0x01c5556a92792c8c";memset(buf, 0, sizeof(buf));
for(int i=0;i<8;i++)
{
int n = strlen(dt) - ((i+1)*2);
sprintf(&buf[i*2], "%c%c", dt[n], dt[n+1]);
}sscanf(buf, "%16I64x", &test);
Kuniva --------------------------------------------