#include #include #include unsigned short getRed(unsigned int); unsigned short getGreen(unsigned int); unsigned short getBlue(unsigned int); void printCell(int); int main() { unsigned int num, combo; unsigned short cred=0, cgreen=0, cblue=0; char chex[8], numhex[8], cell[80]; const unsigned int MAX = pow(2,32)-1; char ch; puts("enter sets of three integers between 0 and 2^32 - 1, type ^d to stop"); printf("\n"); printf("\n"); ch = getchar(); do { printf(""); // repeat three times for (int count = 1; count <= 3; count++) { // read num if (! isdigit(ch)) // bad input return 1; num = 0; while (isdigit(ch)) { num = num * 10 + ch - '0'; ch = getchar(); } while (isspace(ch)) { ch = getchar(); } if (num > MAX) // bad input return 2; printCell(num); if (count == 1) cred = getRed(num); if (count == 2) cgreen = getGreen(num); if (count == 3) cblue = getBlue(num); } // for each number combo = (((cred << 8) + cgreen) << 8) + cblue; printCell(combo); } while (ch != EOF); printf("
\n\n"); return 0; } void printCell(int num) { int comp = ~num; printf("#%06x\n", num, comp, num); } unsigned short getRed(unsigned int n) { // n = n & 0x00FF0000; // mask the red bits // return (unsigned short) (n >> 16); n = n >> 16; n = n & 0x000000FF; return (unsigned short) n; } unsigned short getGreen(unsigned int n) { n = n >> 8; n = n & 0x000000FF; // mask the green bits return (unsigned short) n; } unsigned short getBlue(unsigned int n) { n = n & 0x000000FF; // mask the blue bits return (unsigned short) n; }