| 1. Is unary (has a single operand)? |
| 2. Uses the ~ operator to "flip" (reverse) the bits within
an integer value. If a bit is "on" it is turned "off".
If a bit is "off" it is turned "on". |
| |
| For example, |
if
byte a = 17; // Binary value: 0001 0001 Hex value: 11
byte b;
after executing the statement
b = (byte) ~a;
|
| variable b will have a value of -18 (because 0001
0001 reverses to 1110 1110). Once again, the cast is needed in order to
store the int value that results from the operation. |
| |
| Example: |
|