--- In [email protected], Jos Timanta Tarigan <jos_t_tari...@...> wrote:
>
> so im currently try to read a binary file and try to represent it in rgb 
> image. i save the file into char[length] and then try to convert it to int to 
> get 0-255 value. is it ok to do it explicitly eg. (int)thisChar ? i got an 
> unexpected value and i wonder if that caused by it. 

If char is signed, then it has range -128..127. If you read binary value 130, 
as a signed char this has value -126:

#include <stdio.h>

int main(void)
{
    signed char c = 130;
    int i = c;

    printf("%d\n", i);

    return 0;
}

This outputs -126. So what you need is an unsigned char:

#include <stdio.h>

int main(void)
{
    unsigned char c = 130;
    int i = c;

    printf("%d\n", i);

    return 0;
}

This outputs 130. So try using unsigned char[length] in your code.

HTH
John

Reply via email to