This content has been marked as final. Show 2 replies
Welcome to the forum!
byte b = (byte) 0x55; //01010101;
byte c = (byte) ~b;
Time for you to download The Java Language Specification and start your way through it. You should also take time to review The Java Tutorials - Start with the 'Getting Started' link on this page
The '<<' is the left shift operator
See section 15.19 Shift Operators in the Java Language Specification
15.19. Shift Operators
The operators << (left shift), >> (signed right shift), and >>> (unsigned right shift) are called the shift operators. The left-hand operand of a shift operator is the value to be shifted; the right-hand operand specifies the shift distance.
. . .
So 'm << 3' shifts the value in m three binary places to the left. The original leftmost three bits are lost and the rightmost three bits become zero.
The '~' is the Bitwise Complement Operator. See Section 15.15.5 of the same doc
15.15.5. Bitwise Complement Operator ~
The type of the operand expression of the unary ~ operator must be a type that is convertible (§5.1.8) to a primitive integral type, or a compile-time error occurs.
Unary numeric promotion (§5.6.1) is performed on the operand. The type of the unary bitwise complement expression is the promoted type of the operand.
At run-time, the value of the unary bitwise complement expression is the bitwise complement of the promoted value of the operand. In all cases, ~x equals (-x)-1.
So if byte b = 01010101 then ~b = 10101010; every bit is complemented - a one bit becomes a zero bit and a zero bit becomes a one bit.