AtomSoft Well-Known Member Nov 29, 2009 #1 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 ?
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 ?
K kchriste New Member Forum Supporter Nov 29, 2009 #2 int result = 16; unsigned char destination; destination = (unsigned char)result;
AtomSoft Well-Known Member Nov 29, 2009 #3 Awesome!!! i had code somewhat like that but it was a pointer version heh The * just had to come off .... Thanks a bunch
Awesome!!! i had code somewhat like that but it was a pointer version heh The * just had to come off .... Thanks a bunch
K kchriste New Member Forum Supporter Nov 29, 2009 #4 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.
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.
Mr RB Well-Known Member Nov 29, 2009 #5 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.
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.
AtomSoft Well-Known Member Nov 29, 2009 #6 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;
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;