I've always dealt with unsigned numbers but for some weird reason they're not working in this code.
Here is the function I have
string compare (unsigned char H[4])
{
unsigned int sum = H[3] + H[2] * 0x100 + H[1] * 0x100 * 0x100 + H[0] * 0x100 * 0x100 * 0x100;
switch(sum)
{
case 0x414b4220: return "akb"; break;
case 0x89425446: return "png"; break;
case 0xefbbbf3c: return "plist"; break;
case 0x4c574600:
case 0x5df90000: return "lwf"; break;
case 0x4a4d5000:
case 0x424d4900:
case 0x434c5300:
case 0x43485000:
case 0x53544700:
case 0x4d415000: return "bin"; break;
default: return "";
}
}
The function is being called this way:
unsigned char C[4];
fin2>>C[0]>>C[1]>>C[2]>>C[3];
string ext = compare(C);
The output I'm getting for the value of sum is always 0x89425446, however the value return is always "". So where am I going wrong?
Note: Sometimes the output I get is 0x80000000