I'm trying to take in user input (which should be an integer), convert that to binary, flip the binaries and then print the decimal version of the flipped binaries.
When I test it with 4294967295 (which is the maximum number for 32-bit) it SHOULD return 0 once it's all flipped. I'm getting 2147483648 instead. Anything wrong with my program?
1 2 3 4 5 6 7 8 9 10 11 12 13
usingnamespace std;
int main() {
int count;
cin >> count; //expecting user input to be of type int
int *array = newint[count];
for (int i = 1; i <= count; i++) {
cin >> array[i]; //user input at index 0, 1, 2, etc...
bitset<32> myBits (array[i]); //the binary version of the decimal at index 0, 1, 2, etc...
bitset<32> invertedBits = ~myBits; //flip all the bits
cout << invertedBits.to_ulong() << endl; //print the decimal version of the bitsets
}
}