Good day. I am learning Java and this question has appeared:
What is the x variable after the next line?
int x = (-14) | 7; The fact is that here the correct answer was -9.
I reasoned like this, in the binary number system 14 is represented as 1110. But since the number 14 with the sign "-" then it turns out that you need to use additional code. It turns out that for the number 14 the additional code is equal to:
1110 ->0001(инвертируем все разряды)->0010(добавляем +1)->10010(Дописываем слева знаковый единичный разряд) Now we perform the logical OR operation on two binary representations of numbers:
10010 + 00111 and it turns out 10111 that in translation into an integer equals to 23. Explain, please, what am I doing wrong? It seems everything is by the rules, but the result is still not correct. Thank you in advance.