I have written a little program in c++ to show the binary equivalent of a number:
But now I want to do the opposite: I want to give a number in binary code and see it normally. for example I want to give "00001010" and receive "10" as a result. how do I do this?
I tried working with arrays (giving the number in an array) and then working with the array positions one by one to see if the number in place is "0" or "1". But I received an error saying that ISO C++ forbids comparison between pointers and integers...
What can I do?
Code:
void dispbinary(unsigned u){
int t;
for(t=128; t>0; t=t/2){
if(u & t) cout << "1";
else cout << "0";
}
}
I tried working with arrays (giving the number in an array) and then working with the array positions one by one to see if the number in place is "0" or "1". But I received an error saying that ISO C++ forbids comparison between pointers and integers...
What can I do?