Search code examples
c++c

Character array typecasting to integer


I have a char array and it holds value 0x4010, i want this value into an unsigned short varaible. I did this by using atoi but getting short value as 0

unsigned short cvtValue = (unsigned short) atoi(aclDta);

character for 0x10 is DEL, i hope it is because of this. Decimal is 6416


Solution

  • You don't need to convert the data with atoi, just cast it:

    unsigned short cvtValue = *(unsigned short *)aclDta;