I am finding it very confusing as to exactly how you get the values in binary form
Computers store everything in binary format, so that is what you start with. Then, you can choose what format you want to use to display the binary number: decimal, hex, oct, etc.:
Code:
#include <iostream>
using namespace std;
int main()
{
int my_num= 25343;
cout<<my_num<<endl; //dec is the default
cout<<showbase;
cout<<hex<<my_num<<endl;
cout<<oct<<my_num<<endl;
return 0;
}
The standard template library has a bitset type which can be used for displaying numbers in binary format. The bitset type also has a flip() function. Here is an example:
Code:
#include <iostream>
#include <bitset>
using namespace std;
int main()
{
bitset<32> myBinary(13);
cout<<myBinary<<endl;
myBinary.flip();
cout<<myBinary<<endl;
return 0;
}