Saturday, November 27, 2010

Converting an Integer to Less Bits

When converting an integer into an unsigned integer with less bits, the MSBs are lost.

The following program demonstrates this:

#include <iostream>
using namespace std;
int main() {
   unsigned char c = 0xabcd;
   cout << "c: " << hex << static_cast<int>(c) << endl;
   return 0;
}

No comments:

Post a Comment