INT to Char

Status
Not open for further replies.

AtomSoft

Well-Known Member
Hey guys i have a number lets say 255 (0xFF)

I want to add 8 to it to make 0x0107(263) then divide it by lets say 16 to get approx 16 as the result (0x0010) now the problem is placing that new value into a char?

How can i place 0x0010 in to a char to make 0x10 ?
 
Awesome!!! i had code somewhat like that but it was a pointer version heh

The * just had to come off .... Thanks a bunch
 
Without the * it is called a CAST. It is not always needed in C, but it is one way to assure that the compiler does exactly what you want.
 
Since this is for a corrected integer rounded division you could do this;

Code:
unsigned char result;
if(blah > (255-8)) result  = 16;
else result = ((blah+8) / 16);

Which gives exactly the same output but only requires a char variable for result, saving one ram and a heap of ROm as it doesn't need any 16bit math.
 
This is my current routine: converts 8 bit RED to 4 bit RED:

Code:
        temp = (((UINT)buff[5] + 8) /16);
        if(temp == 16) temp-=1;
        buff[5] = (BYTE)temp;
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…