   odd problems with % operator result when turning it into a unsigned char variable
This may not be the right forums for this question but it kind fits in a few places. This comes from a current project of mine which is a random height map generator. I recently modifyed it to work with heights beyond 255 so it is useing doubles to do this. I made a mini map that showed a greyscale image of it so i tryed to get it to show in greyscale then other color types to make it slightly more useful. First off is the code. It is cut a bit to show the code dealing with my problems (I mean there is more there but its not relevent). What is not shown is that buffer[] is a double pointer to a array of data, data[] is a pointer to a array of unsigned char, RemanderOutput is a file output object from ofstream, and Width and Height are int's defined else whereint x, z, Remander, temp;x = 0;z = 0;for(x = 0; x < (Width * Height); x++) {temp = buffer[x];Remander = temp%255;if(buffer[x] <= 255) {Data[z] = buffer[x];z++;Data[z] = buffer[x];z++;Data[z] = buffer[x];z++;}//end buffer[x] <= 255 if//red if'sif(buffer[x] > 255) {if(buffer[x] <= 510) {if(Remander == 0) {Data[z] = 255;z++;Data[z] = 0;z++;Data[z] = 0;z++;}//end Remander ifelse {RemanderOutput << "Remander: " << Remander << std::endl;Data[z] = Remander;RemanderOutput << "Data: " << Data[z] << std::endl;z++;Data[z] = 0;z++;Data[z] = 0;z++;}//end else}//buffer[x] <= 510}//buffer[x] > 255  When i run my program and make the heightmap i output the data for the else to a text file. Remander seems to have the right value. However when i assign it to Data[z] it gives me a value of . I am not real use to using the % operator. only done it a few times and never ran into this befor and any information on why this is happening would be apreciated   
  It doesn't look like it has anything to do with the % operator. Rather, it has everything to do with the fact that you're outputting a char, which outputs an ASCII* character rather than the textual representation of an 8-bit number. If you want that, cast it to int. For instance:char c = 65;cout << c << endl; // Outputs "A"cout << (int)c << endl; // outputs "65"BTW: Your problems with localizing this bug are directly caused by the fact that you're using output statements to do your debugging. If you learn how to use the debugger, these issues will be trivial to pinpoint and fix.*Or EBCDIC, if you're kicking it old school.   ;Quote:*Or EBCDIC, if you're kicking it old school.Does anybody still kick it that old school?;You where right and i want to ask if you know of any tutorials on how to use Visual Studio Net's debugger.   ;Hottentot;  FYI, x%y will be a number less than y. That is to say, I think:Remander = temp%255should be either:Remander = temp%256; or Remander = temp&255;   ;  Also FYI, it's spelled "remainder", with an i. :)   