Hi guys I'm trying to write a program to convert ASCII code into binary but it is not working properly.
Code:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
char character;
int i;
int m[8];
cout<<"Please enter a character: ";
cin>>character;
cout<<"You've entered "<<character<<endl;
for(i=0;i<8;i++)
{
m[i]=character%2;
character = character/2;
}
int top, bottom;
for(bottom=0,top =7; bottom<8; bottom++,top--)
{
m[bottom]=m[top];
cout<<m[top];
}
return 0;
}
This is what I have so far. It works for the letter 'A' but it also output the identical binary number for B or C and it goes completely crazy if I type in 'V'.
Please help me find the error.