2 Chars to Short in C
问题 I've got 2 chars. Char 128 and Char 2 . How do I turn these chars into the Short 640 in C? I've tried unsigned short getShort(unsigned char* array, int offset) { short returnVal; char* a = slice(array, offset, offset+2); memcpy(&returnVal, a, 2); free(a); return returnVal; } But that didn't work, it just displays it as 128 . What's the preferred method? 回答1: I found that the accepted answer was nearly correct, except i'd run into a bug where sometimes the top byte of the result would be 0xff