In Java, applying bitwise NOT to 5 yields which value?

Prepare for the Computer Programming Test. Study with flashcards and multiple choice questions, each question has hints and explanations. Get ready for your exam!

Multiple Choice

In Java, applying bitwise NOT to 5 yields which value?

Explanation:
Bitwise NOT flips every bit in the value. In Java, int is a 32-bit signed two’s complement number. The binary for 5 is 00000000 00000000 00000000 00000101. Flipping all bits yields 11111111 11111111 11111111 11111010, which is -6 in two’s complement representation. A handy way to see it is ~x = -x - 1, so ~5 = -5 - 1 = -6.

Bitwise NOT flips every bit in the value. In Java, int is a 32-bit signed two’s complement number. The binary for 5 is 00000000 00000000 00000000 00000101. Flipping all bits yields 11111111 11111111 11111111 11111010, which is -6 in two’s complement representation. A handy way to see it is ~x = -x - 1, so ~5 = -5 - 1 = -6.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy