Search This Blog

Wednesday, September 30, 2009

C++, Signed Char and Two's Complement

#include
Remember: when all bits on a signed char, it's -1

using namespace std;
int main()
{
char i = 0xff;
cout << (int)i << j =" 0x7f;" k =" 0;" style="font-weight: bold;"> (0 111111)

/*
-128 (ONLY signed bit on) (1 000000)
-127
.
.
-1 (all bits on) (0xff, or, 1 111111)
0 (all bits off)
1
*/
}
}

No comments: