Java beginners often ask the same type of questions, and of them is what is the difference between & and && operator in Java or the difference between | and || operators? The standard answer to this question is well, the main difference between & and && is that the former is a bitwise operator, and && is a logical operator in Java. That's academic until you clearly explain the difference in working of & and && or | and ||. For absolute beginners, & is used to represent AND logic operation in Java and | is used to represent OR logic operation.
Thursday, August 18, 2022
Wednesday, July 28, 2021
Difference between Right shift and Unsigned right shift in Java ( >> and >>> ) Example
There are two types of right shift operator in Java >> and >>>, former is known as right shift and later is known as right shift with zero fill or simply unsigned right shift operator in Java. Though both of them are known as bit shift operators and moves bits patterns towards right hand side of a bit sequence, there is a subtle difference between them. When we use right shift operator i.e. ">>" it keeps the sign bit intact i.e. if the original number is negative then it will remain negative even after right shift i.e. first or most significant bit never lost, doesn't matter how many times you shift.
Labels:
core java
,
Java bit manipulation tutorial
Tuesday, July 27, 2021
Bitwise and BitShift Operators in Java - AND, OR, XOR, Signed Left and Right shift Operator Examples
Bitwise and Bit Shift Operators in Java are a powerful set of operators
that allows you to manipulate bits on integral types like int, long, short,
bytes, and boolean data types in Java. Bitwise and Bit shift operator is among
the fastest operator in Java but still, many Java programmers don't familiar
with bitwise and bitshift operations, especially those who don't come from C programming
backgrounds. If you have already learned C or C++ before starting with Java
then understanding bitwise and bitshift operators
are quite easy in Java, because it's similar to the bitwise operation in C.
Subscribe to:
Posts
(
Atom
)