From: boylesgj AT lion DOT cs DOT latrobe DOT edu DOT au (Gregary J Boyles) Newsgroups: comp.os.msdos.djgpp Subject: Char/unsigned/unsigned char conversion problems. Date: 16 Feb 1997 10:16:57 GMT Organization: Comp.Sci & Comp.Eng, La Trobe Uni, Australia Lines: 62 Distribution: world Message-ID: <5e6mqp$6ah@lion.cs.latrobe.edu.au> NNTP-Posting-Host: lion.cs.latrobe.edu.au To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp I am moving characters + text attribute to a window, which is later copied directly to video RAM. The window is stored as a 1D array and the text attribute is an unsigned with the lower byte zeroed. The function : void WindowC::Write(char Ch) { Window[Index]=Attribute | (unsigned)Ch; } In one example of using this function I should have seen a light grey character on a blue back ground. I.E. 0 001 0111 10110011 | | | | | | | +------ASCII 179 | | +-------------light grey fore ground | +------------------blue back ground +---------------------non blinking Instead I saw a white flashing character on a light grey back ground. I.E. 0 001 0111 10110011 | | | | | | | +------ASCII 179 | | +-------------white fore ground | +------------------light grey back ground +---------------------blinking I was assuming that the upper byte would be zeroed in the conversion (unsigned)Ch. I.E. char : 10110011 -----> unsigned : 0000000010110011 Is this assumption wrong and the upper byte could be anything? Originally the function was as follows: void WindowC::Write(unsigned char Ch) { cout< Window[Index]=Attribute | (unsigned)Ch; } However passing a space character (' ') to this function resulted in a '3' being written to stdout and passing ASCII 179 to it resulted in '-' being written to stdout. Can some one explain what is happening in the conversion from char to unsigned char.