I have written a function which read some bytes then convert it to int type
and I want it still keep the negative number, ex: 0xFFFF = -1
my sample code:
That is read 3 bytes, If it read 0xFFFFFF, the value is 16777215.Code:
FILE * fp;
int value = 0;
int read_num = 3;
fread(&value, read_num, 1, fp);
But I want get the negative number -1.
And, If read 2 (or 4 bytes), the 0xFFFF (or 0xFFFFFFFF) also need to convert to -1.