-
Binary converter
I don't know if anyone has made on but this is kind of a brute force method... check it out.
Code:
// Phillip Hermans
// Feburary 18, 2003
#include <iostream.h>
int main()
{
int i,ent,x = 128,wot,q;
do{
cout << "Enter a number greater than 0 and less that 256: ";
cin >> ent;
}
while(ent > 256 || ent < 0);
wot = ent;
for(i = 1; i < 9; i++)
{
if(x > wot)
cout << "0";
else
{
cout << "1";
wot = wot % x;
}
x /= 2;
}
return 0;
}
Like it?
-
bitset
There's a class called bitset. I think its part of the STL (standard template library). It's very easy to display a number in binary using bitset. (I have an example at home, and I could post it later.) There was a post a few weeks ago showing how to use it too. So, you might want to search.
[edit]
You'll need to include the header file bitset.h
-
This will display byte x in binary:
Code:
#include <bitset>
cout << bitset<8>(x)
The attached sample program uses various bases.