Bit Tricks

The basic Bit Operations are & (AND) , |(OR) , ^(X-OR), ~(Negation).

Checking nth bit set or not

Let ‘x‘ be the given number.

 (x & (1<<n)) >> n

Setting the nth bit of number

x = ( x | (1<<n) )

Continue reading

Advertisements

Pop Vs Imap Protocol

Both POP3 and IMAP protocol are used for email retrieval process.

Pop Protocol

  • Pop protocol downloads the mail from the server, stores it locally and deletes from the server.
  • POP3 is useful only when you access email from only one computer.
  • POP3 is a one-way communication.
  • All mails are stored locally and without internet connection we can access them.
  • When the mail is accidentally deleted, we cannot recover it.

IMAP Protocol

  • IMAP protocol connects the remote server, caches the mail locally and then disconnects from the server.
  • IMAP is useful when you want access e-mail from multiple systems.
  • IMAP is a 2-way communication

Puzzle – A Bird and Two Trains

Puzzle

Consider two trains starting from two points X and Y respectively. Trains which starts from X travels at 15 Km/hr while the train which starts from Y travels at 20 Km/hr. Both trains start at the same time. A Bird also start from X at the same time. The speed of the Bird is 25 Km/hr. The Bird flies from X to Y until it meets the train started from Y. After that it changes its direction and fly towards the train started from X. When it meets X it start flying toward Y and so on until the train meets. What is the total distance covered by the bird ?

Hint : Think Simple !

Continue reading

Puzzle – A Gold For 7 Days

Puzzle

A loyal worker is working under you for 7(seven) days and you have only one gold bar to pay him. You must pay the worker at the end of each day. Otherwise, he wont come for next day’s work. One more constraint is you have to make only two cuts in the gold bar. How can you pay him at the end of each day ?

Hint:   Barter System

Continue reading

Puzzle – Three Ants Problem

Puzzle

Three ants are sitting in the corners of the equilateral triangle. All ants start at same time and move at same speed constantly. The speeds of three ants are equal. Each ant picks up a direction randomly at first and moves in that direction. What is the probability that none of the ants will collide with each other ?

Continue reading

Puzzle – Red and Blue Marble

Puzzle

We have 50 Red , 50 Blue Marbles and 2 jars. One of the jar is chosen at random and then one marble is chosen from that jar at random. How would we maximize the chance of choosing red marble ? What is the probability of choosing red marble ?. All 100 marbles should be placed in the jar.

Continue reading