I just thought of putting this code up because some people were asking how to convert a decimal number to 8 bit binary number. So here is a little code:
PHP Code:#include <iostream>
#include <string>
using namespace std;
/*****************************************************************
Thanks to everybody who helped me.
GOD BLESS THEM..
I am only 92:o
$$$$$$$$$$$$$$$$$$$$$$$$$$
ALL ABOVE COPIED FROM TOM's main coding comments:D;)
****************************************************************/
//Function to convert decmial number to its binary form
string dectobin(int what)
{
char bin[10] = "";
int dvs = 128;
while (dvs>=1)
{
if (what >= dvs)
{
what = what - dvs;
strcat(bin,"1");
}
else
{
strcat(bin,"0");
}
dvs = dvs/2;
}
return bin;
}
//An example of using the above function
int main()
{
int x;
cout<<dectobin(195)<<endl;
cin>>x;
return 0;
}
Like the title comments?![]()




Reply With Quote