December 11, 2005

The bit logics; this two digits 1 and 0 can cause chaos

Are you a typical programmer who appreciates a diferent way of doing something? then you will definitely like this blogpost. After several months of thinking in terms of objects, believe me, it will be so difficult for anyone to come down to a level of thinking in terms bits. Cant believe it? then try to solve the following three programming puzzles.

Q1. Quickly find if a given number is a power of two or not?
Q2. Write logic to count the number of ones in a 32 bit unsigned integer? and finally
Q3. I have an array of numbers out of which all the numbers are occuring even number of times except for one that occurs odd number of times. Write a logic to find this number that is appearing odd number of times in the array?

If you have solved them without using bit level operations, thats fine, now try to solve them using bit level logic.

The Answers.
Ans1. If a number is a power of two then only one bit is 'on' in the bit representation of the number. Example int 2 is represented in binary as 0010, integer 4 is 0100, integer 8 is 1000. All the time if a number is a power of two there is only one 1 bit in the bit representation of the number. Now what? Try to make use of this property to find if a number is a power of two. Here we go.
If the number is n and if we do a logical and with (n-1) then all the bits should cancel out. so if n &(n-1) == 0 then the number is a power of two.

Ans2. After understanding this logic I now really have a tough time to explain it. Think on this. If I do something like this, what will happen?
n = n&(n-1);
if the number is 11. and we do n&(n-1) ie (1011) & (1010) n becomes (1010). making the last one bit in the bit representation of n, disappear. Now n =10 ie (1010) and now if we do n&(n-1) again then the last one bit in n will again disappear. Thus the algorithm goes as follows

unsigned count_ones(unsigned num){

unsigned count = 0;

while (num)
{
num &= num - 1;
++count;
}

return count;
}
Spend some time on it you will understand.

Ans3. This is a tricky question too. You should be knowing what xor does?
1 ^ 1 is 0
1 ^ 0 is 1
0 ^ 1 is 1
0 ^ 0 is 0
whats with this? If you xor a number with itself we get zero right? and if we agian xor zero with the number we get back the number. That means if we xor a number the even number of times then the result is zero and if we xor the number odd number of times the result is the number itself. eg x = 7 ^ 7 ^ 7 implies x is 7.

Now take an array of some numbers 2,5,6,2,5,5,6 if we keep on xoring the numbers ie 2 ^ 5 ^ 6 ^ 2 ^ 5 ^ 5 ^ 6 in this series of xoring the numbers that are appearing even number of times will cancel out to zero and the only number that is appearing odd number of times will be the result of the operation of xoring the whole array. we got the number, we wanted.

Enjoyed it, now if you are of the opinion that such answers cannot be expected of a candidate in an interview, then Iam with you. I agree that it is very rare that such a logic will strike your mind in the interview. Most of the times one can answer the question only if he/she read about the logic somewhere.

November 07, 2005

My idea of a good corporate desktop screen saver

The other day I was looking at my PC and was not happy to see the same old screensaver and press alt+ctl+DEL to unlock screens. I started dreaming on what could be better than the current ones and checkout what came to my dreams?
Cool to have features.
1. On the screen saver visitors to your place should be able to type into the screen with section "when you were not at your desk".
2. Ability to leave a voice message will still be better.
3. With the advent of ubiquitous mobile technology and if you could have a way to connect your cell phone with your computer wirelessly it would be wonderful if your distance from your desktop can be displayed on the screen saver.

What more can we ask for? A live satellite video feed of my current location onto my desktop....Iam just kidding.

Does Software Expire?

The Question may sound meaningless but it can be a good discussion starter. And my starting point of view on the topic is Yes! Software expires, thats the reason why we create all new requirements and renovate software often. My extention to this point is even you continue to renovate, make enhancements and no matter what you do software still expires or gets out dated.

The example to this is observing the Internet Explorer browser. ie was designed longback probably with a best design. Over a long term it sure would have undergone so many changes and now if you compare it today with mozilla firefox(Iam not saying its inferior or superior) you can see that ie was not targetted at tabbed browsing at all and the solution implemented for this tabbed browsing in msn toolbar download is not quite appealing. This is a symptom that over a period of time software grows to a point that any more changes will not cover its outmodishness and hence it moves towars the direction of expiry unless you redesign the major part of the code and give the same name to it.

Another noteworthy example to this discussion is the introduction of object oriented programming in perl. Its really hard to do object oriented programming in perl compared to the way we do in c++ or java. Thats the reason why the perl6 team is going with a new design from the scratch with one of the aims to support object orientedness.

September 03, 2005

A list of top security tools appraised

Just stumbled here, turned out to be a very good compilation of network security tools. http://www.insecure.org/tools.html

August 12, 2005

Security Focus.

I was wondering how one can fight system crashes and security attacks because of getting online using windows? It was then I got this crazy idea. Microsoft has a product called virtual pc using which you can have any number of pc based operating systems on your machine. And now find a way to connect to internet only using one of the OSes installed inside the virtual pc. This implies you will not be able to access the internet on the main windows OS. This makes your data and system on the main OS safe and secure. Virtually its the same as if you are accessing the net from a secure sandbox. The whole concept should work well or atleast give a tough time to hackers. Who knows you never know something works until somebody finds a way to break this virtual barrier too.

August 07, 2005

A Bit skeptic about WiFi

Can this be true? here. I dont really understand much of whats said in there until I try that on my own. But the users are warned to be privacy and security savvy. A good to know thing.

July 13, 2005

An incomplete List of all areas u can do IT business

An incomplete List of all areas one can do IT business, Suggestions welcome

1. Write security software Norton,symantic
2. Write Content management softwares EMC
3. ERP Applications Oracle, SAP
4. Operating systems Microsift,IBM
5. Software development tools microsoft, Oracle, eclipse
6. Database, Oracle
7. Write Desktop applications
8. Write web service applications
9. Office automation
10. Write hardware interfaces to software like device drivers etc
11. Write messaging and communication software.
12. Content search software business
13. Advertising software.
14. Unicode and font developers
15. Content presentation software.
16. Graphics software
17. Gaming software
18. Software for audio and video processing
19. Provide services to implementaion of open source products
etc

An overdose of GRE.......very funny

GRE STUDENT : Scintillate, scintillate, asteroid minim.

NORMAL PERSON : Twinkle, twinkle, little star

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

GRE STUDENT : Individuals who make their abodes in vitreous edifices would be advised to refrain from catapulting perilous projectiles.

NORMAL PERSON : People who live in glass houses should not throw stones.

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

GRE STUDENT: All articles that coruscate with resplendence are not truly auriferous.

NORMAL PERSON : All that glitters is not gold.

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

GRE STUDENT : Sorting on the part of mendicants must be interdicted.

NORMAL PERSON : Beggars are not choosers

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

GRE STUDENT : Male cadavers are incapable of rendering any testimony.

NORMAL PERSON : Dead men tell no tales

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

GRE STUDENT : Neophyte's serendipity.

NORMAL PERSON : Beginner's luck

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

GRE STUDENT : A revolving litchi conglomerate accumulates no congeries of small, green, biophytic plant.

NORMAL PERSON : A rolling stone gathers no moss

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

GRE STUDENT: Members of an avian species of identical plumage tend to congregate.

NORMAL PERSON : Birds of a feather flock together

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

GRE STUDENT : Pulchritude possesses solely cutaneous profundity.

NORMAL PERSON : Beauty is only skin deep

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

GRE STUDENT : Freedom from incrustations of grime is contiguous to rectitude.

NORMAL PERSON : Cleanliness is godliness

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

GRE STUDENT : It is fruitless to become lachrymose of precipitately departed lactile fluid.

NORMAL PERSON : There's no use crying over spilt milk

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

GRE STUDENT : It is fruitless to attempt to indoctrinate a superannuated canine with innovative maneuvers.

NORMAL PERSON : You can't try to teach an old dog new tricks

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

GRE STUDENT : Surveillance should precede saltation.

NORMAL PERSON : Look before you leap

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

GRE STUDENT : The person presenting the ultimate cachinnation possesses thereby the optimal cachinnation.

NORMAL PERSON : He who laughs last, laughs best

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

GRE STUDENT : Exclusive dedication to necessitous chores without interludes of hedonistic diversion renders Jack a hebetudinous fellow.

NORMAL PERSON : All work and no play makes Jack a dull boy.

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

GRE STUDENT : Where there are visible vapours having their provenance in ignited carbonaceous materials, there is conflagration.

NORMAL PERSON : Where there's smoke, there's fire!

June 16, 2005

Top 5 sites of the day

creativity @ photography http://www.pixeladdiction.com/
A vast collection of screenplays http://corky.net/scripts/
Learn Biology interactively http://biologyinmotion.com/
All that you wanted to know to start using Linux http://brunolinux.com
customize windows the way you want it to look http://www.annoyances.org/exec/show/category02

See my name in various text graphics........

 /\ ._ o|
/--\| |||         


Have fun. Don´t forget to bookmark

  _
 /_/_  ./
/ // ///



Ofcourse I could not format the better ones here but you can get many such Ascii designs of words here http://www.network-science.de/ascii/

Play with world's companies and their directors......here

A good one http://www.theyrule.net/

Very good collection of Siddu's comments.

Collection of famous quotes by Navjot Singh (The Indian Cricketer)

1. That ball went so high it could have got an air hostess down with it.

2. There is light at the end of the tunnel for India , but it's that of an
incoming train which will run them over.

3. Experience is like a comb that life gives you when you are bald.

4. This quote was made after Ganguly called Dravid for a run and
midway sent him back and Dravid was run out in the third test against
the West Indies at Barbados."Ganguly has thrown a drowning man both
ends of the rope."

5. Sri Lankan score is running like an Indian taximeter.

6. Statistics are like miniskirts, they reveal more than what they hide.

7. Wickets are like wives - you never know which way they will turn!

8. He is like Indian three-wheeler, which will suck a lot of diesel but
cannot go beyond 30!

9. The Indians are going to beat the Kiwis! Let me tell you, my friend that
the Kiwi is the only bird in the whole world, which does not have wings!

10. As uncomfortable as a bum on a porcupine.

11. The ball whizzes past like a bumble -bee and the Indians are in the sea.

12. The Indians are finding the gaps like a pin a haystack.

13. The pitch is as dead as a dodo.

14. Deep Dasgupta is as confused as a child is in a topless bar!

15. The way Indian wickets are falling reminds of the cycle stand at
Rajendra Talkies in Patiala one falls and everything else falls!

16. Indian team without Sachin is like giving Kiss without a Squeeze.

17. You cannot make Omelets without breaking the eggs.

18. Deep Dasgupta is not a Wicket Keeper, he is a goalkeeper. He must be
given a free transfer to Manchester United.

19. He will fight a rattlesnake and give it the first two bites too.

20. One, who doesn't throw the dice, can never expect to score a six.

21. This quote was made after Eddie Nichols, the third umpire, ruled
Shivnarine Chanderpaul 'NOT OUT' in the second test at Port of Spain T&T.
"Eddie Nichols is a man who cannot find his own buttocks with his two hands."

22. Anybody can pilot a ship when the sea is calm.

23. Nobody travels on the road to success without a puncture or two.

24. You got to choose between tightening your belt or losing your pants.

25. The cat with gloves catches no mice.

26. Age has been perfect fire extinguisher for flaming youth.

27. You may have a heart of gold, but so does a hard-boiled egg.

28. He is like a one-legged man in a bum kicking competition.

29. The third umpires should be changed as often as nappies and for
the same reason.

30. Kumble's bowling at the moment is flat as a Dosa.

And Finally the clincher:-

This quote was made when India was losing a match and one of the
fellow commentator made the mistake of saying that things would have
been different had Tendulkar's wicket not
fallen at the wrong time.

My dear, if my aunt was a man she would have been my uncle !!!!

June 13, 2005

www.start.com/3

Its more of a customised newsbot to me. Its cool. I liked it.

June 07, 2005

If you are interested in ciphers and codebreaking and all that cryptography !!!

If you are the one with a Beautiful Mind or some sort of a Robert Langdon of The Davinci Code here is a very nice link for you. Learn in detail about ciphers and code breaking here http://www.vectorsite.net/ttcode1.html

how to surf at work in a restricted place.

Morally not recommended, if your employer does not like it but for information this is a good place to learn about firewall and how to make your surfing encrypted. http://www.buzzsurf.com/surfatwork/

A better Windows explorer for XP

If you are an XP user you should try this. http://www.explorerxp.com/

May 27, 2005

Theorem on Salary... Very funny

The theorem relies on the following 3 postulates:
1. Knowledge is power ie knowledge = power
2. Time is Money ie time = money
3. And every physics student knows power = Work/ Time

Here goes the theorem
Knowledge = Work / Time
and since Time = Money
Knowldege = Work/ Money

Solving for Money

Money = Work / Knowledge

So as knowledge approaches Zero Money approaches to infinity regardelss of work done...........

Conclusion : The less you know the more you make....

Lessons in Management ........ Very funny

1.) Lesson Number One

A crow was sitting on a tree, doing nothing all day. A small rabbit saw the crow, and asked him, "Can I also sit like you and do nothing all day long?" The crow answered: "Sure why not." So, the rabbit sat on the ground below the crow and rested. All of a sudden, a fox appeared, jumped on the rabbit and ate it.

Management Lesson: To be sitting and doing nothing, you must be sitting very, very high up.

2.) Lesson Number Two

A turkey was chatting with a bull. "I would love to be able to get to the top of that tree," sighed the turkey, "but I haven't got the energy. "Well, why don't you nibble on some of my droppings?" replied the bull. " They're packed with nutrients." The turkey pecked at a lump of dung and found that it actually gave him enough strength to reach the first branch of the tree. The next day, after eating some more dung, he reached the second branch. Finally after a fortnight there he was proudly perched at the top of the tree. Soon the turkey was spotted by a farmer, who promptly shot him out of the tree.

Management Lesson: Bullshit might get you to the top, but it won't keep you there.

3.) Lesson Number Three

When the body was first made, all the parts wanted to be Boss. The brain said, "I should be Boss because I control the whole body's responses and functions." The feet said, " We should be Boss as we carry the brain about and get him to where he wants to go. The hands said, "We should be the Boss because we do all the work and earn all the money. "And so it went on and on with the heart, the lungs and the eyes until finally the asshole spoke up. All the parts laughed at the idea of the asshole being the Boss. So the asshole went on strike, blocked itself up and refused to work. Within a short time the eyes became crossed, the hands clenched, the feet twitched, the heart and lungs began to panic and the brain fevered. Eventually they all decided that the asshole should be the Boss, so the motion was passed.

Management Lesson: You don't need brains to be a Boss, any asshole will do.

4.) Lesson Number Four

A little bird was flying south for the winter. It was so cold, the bird froze and fell to the ground in a large field. While it was lying there, a cow came by and dropped some dung on it. As the frozen bird lay there in the pile of cow dung, it began to realize how warm it was. The dung was actually thawing him out! He lay there all warm and happy, and soon began to sing for joy. A passing cat heard the bird singing and came to investigate. Following the sound, the cat discovered the bird under the pile of cow dung, and promptly dug him out and ate him!

Management Lessons:
a) Not everyone who drops shit on you is your enemy.
b) Not everyone who gets you out of shit is your friend.
c) And when you're in deep shit, keep your mouth shut.

5.) Lesson Number Five

A man was in a hot-air balloon. Soon he found himself lost with nothing but green fields for as far as the eye could see. Eventually, he happened to float over a man who was walking his dog. He leaned over the basket and yelled out, "Hello! Where am I?" The man on the ground replied, "You're about 20 feet above the ground in a hot- air balloon." The balloonist cursed him and shouted back, "You must be a statistician." "Why do you say that?" asked the man on the ground. "Well," shouted the balloonist, "You're absolutely correct but your answer was completely useless." "Oh I see," replied the walker, "And you must be a manager." "Actually, you're right," said the balloonist. "How did you know?" "Well," said the walker, "First you were lost. Then, after working out what information you needed to sort yourself out, you asked someone else to get it for you. Now, that you have the information, you're still lost, but it's someone else's fault." Well, Was it interesting?

Management Lessons : Do I need to tell it again !!!!

May 09, 2005

Did u see this from google.

http://webaccelerator.google.com/index.html

cooking with google

is in't this interesting. You go home and u see only few ingredients at home. u enter those ingredients and you will get a list of recipies u can cook with them.
chekout here http://www.researchbuzz.org/cookin_with_google.shtml

April 07, 2005

Here are some tips to spped ur firefox

check the tips here that will speed up your firefox.
http://computerhaven.info/forum/tm.aspx?m=1732&mpage=1&key=ۄ

something strage in MS word.......

got this from a mail of one of my friend....
open a word document and type

= rand(1,1)

press enter.
you will see the following message The quick brown fox jumps over the lazy dog.

could be some kind of a bug........or dont know if it serves any higher purpose.......

April 04, 2005

My theory on Open source ......

I have a feeling!! Software development is easy. Iam a software developer proves my feeling right. Anyone can jump in and start writing useful programs. Thats probably how people started writing and sharing software.

After my little bit of experience in this area I want to write an equation

need/use of a propreitory software is proportional to the open source initiative of the software.

The more there is a need for a software or the more usability of a propreitory software the more quickly people will start writing the same software under the canopy of open source. So Propreitory companies cant just sit and relax after the initial delivery. The cycle goes as follows for a software company

get good ideas ---> implement them ----> earn as much money on that as u can when the iron is hot---> open source will kill u anyway with its free version----> to survive get more good ideas, implement them and continue the cycle. Thats as simple as it gets.......

This how ever does'nt mean open source is good or bad. It however is imperative that open source is driving/chasing the industry for a better place.


January 24, 2005

I am trying SharpReader to read and organize RSS feeds. It seems cool.