I have a little weird problem here! I am trying to write a color table for an 8 bit Windows 3.x bitmap file. I just want the file to be in grayscale, so I'm trying to write bbb0, ggg0, rrr0 256 times, where r = g = b = 1..256
//write greyscale color table for (int i = 255; i >= 0; i--) { writeS = (unsigned short)i; outfile.write ((char*)&writeS,sizeof(char)); // b outfile.write ((char*)&writeS,sizeof(char)); // g outfile.write ((char*)&writeS,sizeof(char)); // r writeS = 0; outfile.write ((char*)&writeS,sizeof(char)); // 0 }
When I look at the output that I get with the hex editor, everything looks fine until I get to number 10, which is written like this:
... 0C 0C 0C 00 0B 0B 0B 00 0D 0A 0D 0A 0D 0A 00 09 09 09 00 08 08 08 00 ...
isntead of:
... 0C 0C 0C 00 0B 0B 0B 00 0A 0A 0A 00 09 09 09 00 08 08 08 00 ...
So, what is strange is that he does this only on this one number, but even more strange is that when I change the code to skip number 10 and write 9 instead, it works.
//write greyscale color table for (int i = 255; i >= 0; i--) { writeS = (unsigned short)i; if (writeS == 10) writeS = 9; outfile.write ((char*)&writeS,sizeof(char)); // b outfile.write ((char*)&writeS,sizeof(char)); // g outfile.write ((char*)&writeS,sizeof(char)); // r writeS = 0; outfile.write ((char*)&writeS,sizeof(char)); // 0 }
gives:
... 0C 0C 0C 00 0B 0B 0B 00 09 09 09 00 09 09 09 00 08 08 08 00 ...
Is something strange happening there with the notation? Any obvious errors that I missed? Has anyone come across anything like this before? Thanks!