fix(guide): simplify directory structure

This commit is contained in:
Mrugesh Mohapatra
2018-10-16 21:26:13 +05:30
parent f989c28c52
commit da0df12ab7
35752 changed files with 0 additions and 317652 deletions

View File

@@ -0,0 +1,61 @@
---
title: bitwise operator example
---
# Bitwise operators
## Truth table
![truth table](https://4.bp.blogspot.com/-0KPDI41veH0/V-OtObm_UWI/AAAAAAAAAso/CkTS0zUMGKIjlE3gUD0fMhmp-B0zcfBmACLcB/s1600/Bitwise-truthtable-Javaform.jpg "truth table")
The bitwise operators are similar to the logical operators, except that they work on a smaller scale -- binary representations of data. Any data can be converted to its binary equivalent. Though binary operators work at binary level but they are operated between normal decimal values only.
## Types of Bitwise Operators
### Bitwise OR
Bitwise OR is a binary operator (operates on two operands). It's denoted by |.
The | operator compares corresponding bits of two operands. If either of the bits is 1, it gives 1. If not, it gives 0.
### Bitwise AND
Bitwise AND is a binary operator (operates on two operands). It's denoted by &.
The & operator compares corresponding bits of two operands. If both bits are 1, it gives 1. If either of the bits is not 1, it gives 0.
### Bitwise Complement
Bitwise complement is an unary operator (works on only one operand). It is denoted by ~.
The ~ operator inverts the bit pattern. It makes every 0 to 1, and every 1 to 0.
### Bitwise XOR
Bitwise XOR is a binary operator (operates on two operands). It's denoted by ^.
The ^ operator compares corresponding bits of two operands. If corresponding bits are different, it gives 1. If corresponding bits are same, it gives 0.
### Left Shift
The left shift operator << shifts a bit pattern to the left by certain number of specified bits, and zero bits are shifted into the low-order positions.
### Right Shift
The right shift operator >> shifts a bit pattern to the right by certain number of specified bits.If the number is a 2's complement signed number, the sign bit is shifted into the high-order positions.
### Unsigned Right Shift
The unsigned right shift operator >>> shifts zero into the leftmost position.
### Example bitwise operators :
```java
int a = 60; /* 60 = 0011 1100 represents 60 in binary*/
int b = 13; /* 13 = 0000 1101 */
int c = 0;
c = a & b; /* 12 = 0000 1100 */
c = a | b; /* 61 = 0011 1101 */
c = a ^ b; /* 49 = 0011 0001 */
c = ~a; /*-61 = 1100 0011 :Invert all bits */
// shift operators : zeros are shifted in to replace the discarded bits
c = a << 2; /* 240 = 1111 0000 : Shift left 2 bits*/
c = a >> 2; /* 15 = 1111 */
c = a >>> 2; /* 15 = 0000 1111 : Zero fill right shift*/
```
**FOR FURTHER INFORMATION:** <a href="https://docs.oracle.com/javase/tutorial/java/nutsandbolts/op3.html">Click Here</a>

View File

@@ -0,0 +1,51 @@
---
title: Basic Operations
---
# Basic Operations
Java supports the following operations on variables:
* __Arithmetic__ : `Addition (+)`, `Subtraction (-)`, `Multiplication (*)`, `Division (/)`, `Modulus (%)`,`Increment (++)`,`Decrement (--)`.
* __String concatenation__: `+` can be used for String concatenation, but subtraction `-` on a String is not a valid operation.
* __Relational__: `Equal to (==)`, `Not Equal to (!=)`, `Greater than (>)`, `Less than (<)`, `Greater than or equal to (>=)`, `Less than or equal to (<=)`
* __Bitwise__: `Bitwise And (&)`, `Bitwise Or (|)`, `Bitwise XOR (^)`, `Bitwise Compliment (~)`, `Left shift (<<)`, `Right Shift (>>)`, `Zero fill right shift (>>>)`
* __Logical__: `Logical And (&&)`, `Logical Or (||)`, `Logical Not (!)`
* __Assignment__: `=`, `+=`, `-=`, `*=`, `/=`, `%=`, `<<=`, `>>=`, `&=`, `^=`, `|=`
* __Others__: `Conditional/Ternary(?:)`, `instanceof`
While most of the operations are self-explanatory, the Conditional (Ternary) Operator works as follows:
`expression that results in boolean output ? return this value if true : return this value if false;`
Example:
True Condition:
```java
int x = 10;
int y = (x == 10) ? 5 : 9; // y will equal 5 since the expression x == 10 evaluates to true
```
False Condition:
```java
int x = 25;
int y = (x == 10) ? 5 : 9; // y will equal 9 since the expression x == 10 evaluates to false
```
The instance of operator is used for type checking. It can be used to test if an object is an instance of a class, a subclass or an interface. General format-
*object **instance** of class/subclass/interface*
Here is a program to illustrate instanecof operator:
```Java
Person obj1 = new Person();
Person obj2 = new Boy();
// As obj is of type person, it is not an
// instance of Boy or interface
System.out.println("obj1 instanceof Person: " + (obj1 instanceof Person)); /*it returns true since obj1 is an instance of person */
```