J
J. Campbell
When the bitwise NOT operator, is placed in front of an integer
variable type (bool, char, short, int, long), the return value is a
signed int, regardless of the variable type. An example can be seen
in this code:
#include<iostream>
using namespace std;
int main(){
bool a = true;
bool b = !a;
cout << hex
<< a << endl // 1
<< b << endl // 0
<< ~a << endl // fffffffe
<< dec
<< ~a << endl // -2
<< hex
<< ~~a << endl // 1
<< ~~~a << endl; // fffffffe
cin.get();
return 0;
}
This doesn't see right...a bool that's been bit-notted *should* return
a single bit instead of returning 32-bits!! The same applies to a
bit-notted char...one would expect 8-bits in return.
Any comments
variable type (bool, char, short, int, long), the return value is a
signed int, regardless of the variable type. An example can be seen
in this code:
#include<iostream>
using namespace std;
int main(){
bool a = true;
bool b = !a;
cout << hex
<< a << endl // 1
<< b << endl // 0
<< ~a << endl // fffffffe
<< dec
<< ~a << endl // -2
<< hex
<< ~~a << endl // 1
<< ~~~a << endl; // fffffffe
cin.get();
return 0;
}
This doesn't see right...a bool that's been bit-notted *should* return
a single bit instead of returning 32-bits!! The same applies to a
bit-notted char...one would expect 8-bits in return.
Any comments