Showing posts with label logical. Show all posts
Showing posts with label logical. Show all posts

Saturday, June 17, 2017

Logical and bit wise operators in java

Logical and bit wise operators in java


In java both logical and bitwise operators are used. Logical operator returns the true / false value depends on the condition check and bitwise return the same true / false depends on the condition check but the difference between these operator is that logical operator only work with the boolean value where as bitwise operator work with both boolean and numeral values. How that will we see later in this post.

Logical operator

Logical operator in java only deals with the boolean value that means it will return either true or false depending on the condition check. If we try to use any other data type then it will give compilation error.

There are three types of logical operator i.e 
1> Logical AND  ( && )
2> Logical OR     (  | |  )

3> Logical NOT   (  !  )

Logical AND 

It is represented with the double ampersand ( && ) sign. basically it is a binary operator and both the operand must return either true or false value and no others data type are not acceptable with this operator.

Operand 1               Operand 2               Result 
   True                          True                     True 
   True                          False                    False
   False                         True                     False 
   False                         False                    False

Conclusion: If any of the operand is False then it will return False. 

Now think is there any need of checking if 1st operand is false ?
I think No because it is obvious that it will return false only but if 1st operand is true that means it may true or false so it is mandatory to check 2nd operand as well.


Note :- Compiler does the same that if 1st operand is false then no need to check further it further and hence save some compilation time.
for ex- 

if (  false && true && true && true ) // It will check the 1st operand if it is false then its obvious that whole statement will lead to false only so compiler will not check further. 
You can have any statement in place of true and false here but which returns either true or false value.

Logical OR

It is a binary operator and both the operand must return either true or false value and no others data type are not acceptable with this operator. It is represented like this   (  | |  ).

Operand 1               Operand 2              Result 
   True                          True                      True 
   True                          False                     True
   False                         True                      True 
   False                         False                     False

Conclusion: If any of the operand is True then it will return False
Now think is there any need of checking if 1st operand is true?
I think No because it is obvious that it will return True only but if 1st operand is false then there may be chance of returning true or false so it will be mandatory for compiler to check 2nd operand as well.

Note :- Compiler does the same thing that if 1st operand is true then no need to check it further and hence save some compilation time.

if (  true  | |  false  | |  true  | |  false ) // It will check the 1st operand if it is true then its obvious that whole statement will lead to true only so compiler will not check further. 
Here you can have any statement in place of true and false but it should return either true or false value.

Logical NOT

It is a unary operator and it will always return the result as reverse of its operand. Like if operand is true then it will return false and vice-versa.

Operand 1                    Result 
   True                             False 
   False                            True
  
Conclusion: If the operand is True then it will return False and vice-versa.                 
for ex-

if ( !  true ) // return false 
if ( !  false ) // return true

Bitwise Operator 

It is same as Logical operator but it can operate both with boolean and numeral value. There are four types of bitwise operator i.e
1> Bitwise AND    ( & )
2> Bitwise OR       (  |  )
3> Exclusive OR    ( ^  )
4> Bitwise NOT    ( ~  )    


Why named as bitwise ?

It is because for numeral values it deals bit by bit. How it deals bit by bit we will see later in this post.

Bitwise AND

It is a binary operator and represented with a single ampersand ( & ).It works same as logical operator in case of boolean value but how it works with numeral value is bit interesting .


How Bitwise AND works with the numeral value?

It deals with each bit that means it will result as 0 always and 1 when both the value are 0.Now think in zeros and ones. We all know that zero represent always false and one represent true always. 
Here it is also the same story that compiler will compare bit by bit and return the result accordingly.  
for ex-

System.out.println( (1 & 2 ) ) ; // It will display Zero as output.

1-> 01            
2-> 10             
---------
       00 ( 0 )
--------- 

Bitwise OR

It is a binary operator.It works same as logical operator in case of boolean value but how it works with numeral value is bit interesting . It is represented like this ( | ).

How Bitwise OR works with the numeral value?
It is same as Bitwise AND but only difference is it will result as 1 always and 0 when both the value are 0. 

System.out.println( (1  |  2 ) ) ; // It will display Three ( 3 ) as output.

1-> 01            
2-> 10             
---------
       11 ( 3 ) 
--------- 

Exclusive OR

It is a binary operator and represented with ( ^ ) this symbol. It result false when both the operand are either true or false otherwise true So compiler cannot be sure about result unless it checks 2nd operand. 

Operand 1               Operand 2             Result 
   True                          True                     False
   True                          False                    True
   False                         True                     True 
   False                         False                    False

Conclusion : It will return False if both the are operand are have same value either true or false otherwise true. It is same in case of bits also if both the bits are same either 1 or 0 then it will return 0 otherwise 1.

Have fun with code guys. keep experimenting!

Available link for download

Read more »

Sunday, February 19, 2017

Logical House Escape Walkthrough

Logical House Escape Walkthrough


Logical House Escape Walkthrough
Logical House Escape Solution



Full walkthrough solution with step by step information on how to solve this room escape game.  Tips, tricks, and detailed explanations provided in this guide.  All the help you need to escape the logical house... alive!
This is a medium-easy escape.  Play the game here.


Logical House Escape Walkthrough Starts here:

Your adventure starts in the lounge area of the logical house:

Take the red card on the shelf under the TV.
Take the smiley star hanging on the chimes from the ceiling.
Take the smiley face from the coffee table.
Take the green leaf from the plant.

Go right to the orange-and-blue bedroom

Open the middle drawer under the PC desk and take a brown leaf.
Take the red book from the drawer under the bed.
Take another smiley face from the middle drawer to the right of the beds.
Take the blue book from the bookshelf, 3rd from the top.

Go right to the kitchen

Take a white leaf  from the blue flower vase
Open the glass cupboard door and take a blue leaf
Open the cupboard under the sink then take another smiley face.

Go left back to the orange-and-blue bedroom.
Zoom in on the cupboard with postcards under the top bed.
Insert the 4 colored leaves.
The doors will open

Take the green card.

Go right and right again to the master bedroom

Take the green moon from the bowl on the floor.
Take the smiley sun from the green flower vase.

Zoom in on the circle of smileys on the wall
Add the 3 missing smiley faces
The door will open

Take the blue card.

Zoom in on the beige locked drawer with the 3 indented shapes
Add the smiley sun, moon, and star.

Take the blue card from the opened drawer.

Take the box from the 3rd from the top set of drawers.

Zoom in on the circles with the red center on the wall
Add the box.  The box will expose 9 planets (although Pluto is probably not a planet!)
Add the 9 planets (you just have to click on them and the computer will place them!)

Take the golden key.

Zoom in on the red book.
Unlock using the golden key

Add the 4 cards in order from I, II, III, IV
You will get the code:  GOOD LUCK

Read the blue book.
Solve the puzzles:

Circle + Square = 4  (Circle = 0 angles + square = 4 angles = 4)
8 angles - 3 angles = 5
5 angles + 4 angles = 9
0 anfles + 4 angles = 4

Code = 4594

Go to the kitchen and open the kitchen cupboard with the combination lock.  Use the code 4594.

Take the silver key (in the lower left corner)

Go all the way left to the lounge
Open the orange locked cupboard on the wall with the silver key
You will see this puzzle:

Click the blue "click" button on the left until the 6 inner circle colors match the outside cables.
The panel will open.

Type the code GOODLUCK (no space needed)
Click OK and it will show CORRECT.

The door will open and you can escape the logical house.

Well done on a great escape
Hope you enjoyed my walkthrough solution!






Available link for download

Read more »