Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

BITCOMPLIMENT CIPHER: Bitcompliment: encypher messages by flipping the bits in e

ID: 3758941 • Letter: B

Question

 BITCOMPLIMENT CIPHER:  Bitcompliment: encypher messages by flipping the bits in each byte. 1 becomes 0, 0 becomes 1. Using a waterpump program skeleton, compliment (~) each byte's bits before you print them.  Read a character at a time, flip its bits, put the char out, continue until EOF.  Don't overthink it.  This is a chance to show what you've learned so far.  This should take no more than four lines of code. I did it in one line of C with no includes.*  So can you, if you think about it.  Do the work: look up the ~ and understand how it works. Understand cin.get() and cin.put() (or getchar() and putchar().) Only if you understand your tools, can you use them.    *The file bitcomp.c contains two lines, one is a //comment. 

Explanation / Answer

Source Code for bit complement in a given byte of char is below..

#include <stdio.h>


int main()
{
   char ch1, ch2;
   while(ch2!='q')
   {
       ch1 = getchar();
       ch2 = ~ch1;
       putchar(ch2);
   }
   return 0;
}