Operators and Binary Number System|| Java + DSA course || Blog 7

What are operators? 

These are the characters which represents a specific action.

Like , Addition sign(+), Subtraction sign(-), Multiplication sign(*), Division sign(/). We know this signs very well but in this blog we are going to see some more operators and its working.

For a quick overview, we will be learning:

  • Operators
  • Binary number system
  • Bitwise operators

Operators

1. Arithmatic Operators

It contains of basically 5 ways which we know very well

+. Addition operator adds given numbers.eg:4 + 2 = 6

-. Subtraction operator adds given numbers.eg:4 - 2 = 2.

-. Multiplication operator adds given numbers.eg:4 * 2 = 8.

%. Modulo operator tells you the remainder while dividing the numbers.eg:14 % 2 = 0. Since 14 can be directly divided by two. It doesn't live any remainder.

2.Relational Operators

Mostly relational operators give output in the term of true or false. It is used for conditions in language.

==. Equal to. It is used to check whether two arguments are equal to each other

int a = 12;
int b = 12;
if(a==b){
System.out.println("yes");
}

 It will print yes

!=. Not equal to. It is used to check whether two arguments are not equal to each other

int a = 12;
int b = 12;
if(a!=b){
System.out.println("yes");
}else{
System.out.println("no");
}

 Here  a!=b is not true since a and b are both 12. Therefore no will be printed.

>. Greater than is used to check if 1st argument is greater than the other  

<. Greater than is used to check if 1st argument is smaller than the other   

>=.  Greater than is used to check if 1st argument is greater than or equal to the other  

<=. Greater than is used to check if 1st argument is smaller than or equal to the other   

3. Logical Operators

&&. AND operators check whether both conditions are true then only executes code inside the brackets. 

int a = 12;
int b = 12;
if(a == 12 && b == 12){
System.out.println("both are 12");
}

 Both are 12 will be printed.

 ||. OR operators check whether any of both the condition is true then only executes code inside the brackets. 

int a = 12;
int b = 2342;
if(a == 12 || b == 12){
System.out.println("anyone is 12");
}

 anyone is 12 will be printed. Since at least a is 12 from both conditions.

!. NOT checks whether condition is false.

int a = 12;
if(! (a == 13)){
System.out.println("a is not 13");
}

 a is not 13 will be printed. a is not 13.

Binary Number System

A binary code represents text, computer processor instructions, or any other data using a two-symbol system. The two-symbol system used is often "0" and "1" from the binary number system.

Example:

0=0
1=1
2=10
3=11
4=100
5=101
6=110
7=111
8=1000
9=1001
10=1010










































































Bitwise operators 

1. Bitwise AND operator



 This is based on logical operator AND. 

It returns 0 if both bits are 0 and 1 if both bits are 1. If both are different, it returns 0.

2. Bitwise OR operator


 This is based on logical operator OR. 

3. Bitwise XOR operator

 

It returns 1 if not similar. 0 if similar .If both 0 , then returns 0. If both 1, then returns 1.

4. Bitwise NOT operator


 It just reverses the number . If 0 then 1. Same applicable to its vice versa.

 5. Bitwise left shift operator

We shift bits left one space and return 0 in empty places. 

------------------------------------------------------------------------------------------------------------------------


 


 ------------------------------------------------------------------------------------------------------------------------


 6. Bitwise right shift operator

It is opposite of left shift operator.it shifts right.

___________________________________________________________________________________

Checkout:https://javaanddsa.blogspot.com/

Did you like our blog 6??

Tell us in the comment section

 

Comments

Popular posts from this blog

LinkedList Problems for Beginners DSA || Java and DSA course || Blog 17

Introduction to Java || Java + DSA course || Blog 1

LinkedList in DSA || Java and DSA course || Blog 16