I don't understand how the type conversion works on below initialization "unsigned int i = -100;".
My understanding is that -100 is explicitly converted from signed integer to unsigned integer.
signed integer: -100(10) = 10011100(2)
↓↓↓
unsigned integer: ?
Below is the code and output. I got "4294967196" as unsigned int. Why is this number that big? How this type cast works? Thank you for helping me out!
// unsigned int, if 8 bit, range 0 to 255
unsigned int i = -100;
cout << "i = " << i << endl; // I get i = 4294967196
cout << "i(unsigned int) = " << (unsigned int)i << endl; // I get i(unsigned int) = 4294967196
cout << "i(int) = " << (int)i << endl; // I get i(int) = -100
My test environment:
OS: Windows 10 Pro (64 bit)
IDE: Visual Studio Community 2019