#include unsigned int code; unsigned char inbyte; char sInBuff[51] = {0}; DWORD dwBytesRead = 0; printf("Hit any key when finished\n"); // CAUTION: some of this may be repeated from template: don't double-dip while (!kbhit()) { ReadFile(hSerial, sInBuff, 1, &dwBytesRead, NULL); if (dwBytesRead > 0) { // if any bytes inbyte = sInBuff[0] & 0xFF; // mask to 8 bits code = inbyte & mask; // mask to relevant data