Search code examples
c++mfchexstrtol

converting 4byte hex string to integer


I am trying to do a conversion from hex string to integer in a MFC project. The code is like this:

CString sMask = "0xFFFFFFE0";
char* pMaskBuffer   = sMask.GetBuffer(sMask.GetLength());               
sMask.ReleaseBuffer();
char * p = NULL;
long iMask = strtol(pMaskBuffer, &p, 16);

The code was working fine when sMask variable was small.But 4 byte mask is generating strange values. Instead of 4294967264 , i am getting 2147483647. How to overcome this. Help please.


Solution

  • That is because the strtol returns long use this

    unsigned long iMask = strtoul(pMaskBuffer, &p, 16);