Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!

## Calculating the most significant digit:

To calculate the most significant digit of any number log can be directly used to calculate it.

Suppose the number is N then Let double K = Math.log10(N); now K = K - Math.floor(K); int X = (int)Math.pow(10, K); X will be the most significant digit.

## Swapping of 2 numbers using XOR:

This method is fast and doesn’t require the use of 3rd variable.

`// A quick way to swap a and b` `a ^= b;` `b ^= a;` `a ^= b; ` |

## Fast Multiplication or Division by 2

Multiplying by 2 means shifting all the bits to left and dividing by 2 means shifting to the right.

Example : 2 (Binary 10): shifting left 4 (Binary 100) and right 1 (Binary 1)

`n = n << ` `1` `; ` `// Multiply n with 2` `n = n >> ` `1` `; ` `// Divide n by 2` |

## Checking if the number is even or odd without using the % operator:

Although this trick is not much better than using % operator but is sometimes efficient (with large numbers). Use & operator:

`System.out.println((a & ` `1` `) == ` `0` `? ` `"EVEN"` `: ` `"ODD"` `);` |

Example:

num = 5

Binary: “101 & 1” will be 001, so true

num = 4

Binary: “100 & 1” will be 000, so false.