I tried to convert decimal to binary like this: I got input int and a binary int.
int rem;
int bin[32] = {0};
for(int i=0; input != 0; i++) { //making array of binary, but reversed
rem = input%2;
bin[i] = abs(rem);
input = input / 2;
}
for(int i = 0; i < 32; i++) { //reversed binary is put in correct order
binary[i] = bin[31 - i];
}
now I want that if the input is negative like "-5" it gives me the two-complement.
When trying to complement every bit with "~", they turn to "-1" somehow.
for (int i = 0; i < 32; i++) {
binary[i] = ~binary[i];
}