Organizational Research By

Surprising Reserch Topic

extracting the 4 byte of char from char string and convert the first 4 byte to i


extracting the 4 byte of char from char string and convert the first 4 byte to i  using -'c'

I have a char array as string as char *x = "1234 is a test";
here 1234 the first 4 byte is a hex data and i need to extract the data and convert to the interger. Thus first I need to extract the first 4 byte as

char dest[5];
    strncpy(dest, x,4);
    char dest[5]='\0';


now how can i convert this 4 byte char to int and convert to the integer value??
is it possible???

i have tried using strtol(dest, &ptr,16 );

however strtol finds the numerical values and seperates but i need the exact first 4 byte to convert to integer

what i suppose is the data is obtained from network thus without using strtol, I suppose to use hex to decimal conversion. Thus i need to first pack 4 bytes in int type and use this . How to coalesced this 4 byte of char to int??
    
asked Sep 9, 2015 by Christin1871
0 votes
9 views



Related Hot Questions



Government Jobs Opening


...