/** * Get 8 3 bit numbers of the command line (ie, number in range 0-7) * and output the bit from those three numbers. * Either by printing the bits to the screen or by * putting the bits into an unsigned char, then outputiong that * char to the screen every time its gets all 8 bits filled. * * * @author gtowell * Created: April 2021 * Modified: May 2021 * **/ #include int main(int argc, char const *argv[]) { unsigned char output = 0; unsigned int res = 0; int b = 0; for (int i = 1; i <= 8; i++) { int num = argv[i][0] - '0'; //atoi(argv[i]); for (int j = 0; j < 3; j++) { /** * idea, since I only case about bits in positions * 1,2 and 3 (from right), will read bit in position 3, * then shift one to left, read in position 3 again, * etc. Thus get bits out, most significant first. * The result of this is the bits some out in order * But is feels pretty backward * **/ int v = (num & 4) ? 1 : 0; output <<= 1; printf("%d", v); output |= v; num <<= 1; b++; if (b>=8) { printf("\n%d\n", output); b = 0; output = 0; } } } printf("\n"); return 0; }