Simple Bit Manipulation Program
Sample of what output is supposed to look like:
http://img156.imageshack.us/my.php?image=scan1pp0.gif
Basically, I'm supposed to write a program to continually take a set of inputted binary numbers, while displaying the inputted sums in decimal, hex and binary.
Here is a flowchart of how the program is supposed to be done:
http://img165.imageshack.us/my.php?image=scan2ib8.gif
I'm having trouble getting the inputted numbers (which are characters) to be placed into a variable as a real number.
So far this is what I have:
Code:
#include "stdafx.h"
#include "stdio.h"
int main(int argc, char* argv[]) {
unsigned char c, b, n;
int sum, done;
sum=0;
done=0;
int i=8;
n=0;
printf("Enter a binary number:");
c=getchar();
if (c=='q'||c=='Q') {
getchar();
return 0;
} else {
for ( int x = 0; x < 8; x++ ) {
b=c&1;
n=n<<1;
n=b|1;
}
sum=sum+n;
printf("sum = %d decimal %x hex and " , sum, sum);
}
getchar();
return 0;
}
In the second .gif I linked to, it states that after I get the inputted characters into c, I'm supposed to make b= LSB(Least significant bit) of 'c' and then Shift 'n' left 1 bit and insert 'b' into 'n' as the new LSB
I just don't understand how to write the code so that it would continually scan until it has all of the inputted numbers into a variable as a real set of bits.
I thank you for your time and any advice anyone can give.