My GNU GCC compiler does not recognize 00111111b due to the end of "b". I tried "B", and it did not work either. Is there any way that I can express and output const in binary format?
It is easy to output in octal and hexdecimal format, and I am wondering how to replace the "oct" in cout statement so that I can print the result in binary form.
Feel free to let me know if you have any ideas.
============================================
There is not such numeric literal as binary/ So the record (00111111b & 00111111b) is incorrect. You can use hex represenntation of you binary values, for example 0x3F & 0x3F. Though I do not know why you are using the same operands of & operator, because the result will be equal to each of two operands.
There are no binary integer literals in C++. I think hex is often good enough because the digits line up so that each hexadecimal digit represents 4 bits in the number.
EDIT: You can also use std::bitset
1 2 3 4 5 6 7 8 9 10 11
#include <iostream>
#include <bitset>
usingnamespace std;
int main()
{
bitset<8> a("00111111");
bitset<8> b("00111111");
cout << a << " & " << b << " = " << (a & b) << endl;
}