NVIDIA Interview Question
Software Engineer / DevelopersSuppose you have the following...
1st case(positive integer):
8=01000 <= n
7=00111 <= n-1
So 8 & 7 = 0000 = 0
2nd case(0):
0=0000
-1=1111
So 0& (-1)=0000=0
3rd case(neg):
-2^31= 100...0
Boundary check #2:
-1: 111...111
-2: 111...110
2^31-1=0111...111
2^31-2=0111...110
This code reveals if n is -2^31 or ^2^31-1. In english, is it the smallest/greatest integer.
What Khoa said makes sense. If you think of it this way, when you substract 1 from n, it'll read right to left, changing every zero to a 1 and stopping once it hits a 1.
If n&(n-1) equals zero, then it must've inverted n's left most '1', which means that everything before that must been a 0. That means that n is in the form 1000.., making it a power of two.
Look Up Your Birthday And See What You Are..!!
*********
January 01 - 09 ~ Dog
January 10 - 24 ~ Mouse
January 25 - 31 ~ Lion
*
February 01 - 05 ~ Cat
February 06 - 14 ~ Dove
February 15 - 21 ~ Turtle
February 22 - 28 ~ Panther
*
March 01 - 12 ~ Monkey
March 13 - 15 ~ Lion
March 16 - 23 ~ Mouse
March 24 - 31 ~ Cat
*
April 01 - 03 ~ Dog
April 04 - 14 ~ Panther
April 15 - 26 ~ Mouse
April 27 - 30 ~ Turtle
*
May 01 - 13 ~ Monkey
May 14 - 21 ~ Dove
May 22 - 31 ~ Lion
*
June 01 - 03 ~ Mouse
June 04 - 14 ~ Turtle
June 15 - 20 ~ Dog
June 21 - 24 ~ Monkey
June 25 - 30 ~ Cat
*
July 01 - 09 ~ Mouse
July 10 - 15 ~ Dog
July 16 - 26 ~ Dove
July 27 - 31 ~ Cat
*
August 01 - 15 ~ Lion
August 16 - 25 ~ Mouse
August 26 - 31 ~ Turtle
*
September 01 - 14 ~ Dove
September 15 - 27 ~ Cat
September 28 - 30 ~ Dog
*
October 01 - 15 ~ Monkey
October 16 - 27 ~ Turtle
October 28 - 31 ~ Panther
*
November 01 - 16 ~ Lion
November 17 - 30 ~ Cat
*
December 01 - 16 ~ Dog
December 17 - 25 ~ Monkey
December 26 - 31 ~ Dove.
*****
If you are a DOG :
A very loyal and sweet person.
Your loyalty can never be doubted. You are quite honest and sincere when it comes to your attitude towards working. You are a very simple person, indeed.
Absolutely hassle free, humble and down-to-earth. That explains the reason why your friends cling on to you.
You have a good taste for clothes.
If your wardrobe is not updated with what is trendy, you sure are depressed. Popular and easy-going.
You have a little group of dignified friends, all of them being quality-personified...! Repost This If It's True For You.!! 4 years of bad luck if you do not share this post.
*****
If you are a MOUSE:
Always up to some sort of a mischief. The mischievous gleam in your eyes is what makes you so cute and attractive to everyone.
You are an extremely fun-to-be-with kind of person.
No wonder people seek for your company and look forward to include you for all get-together's. However, you are sensitive which is a drawback. People need to select their words while talking to you.
If someone tries to fiddle around and play with words while dealing with you, it is enough to invite your wrath. God bless the person then..! Repost This If It's True For You.!! 3 years of bad luck if you do not share this post.
*****
If you are a LION :
Quite contradictory to your name, you are a peace loving person.
You best try to avoid a situation wherein you are required to fight. An outdoor person, you dislike sitting at one place for a long duration. Popular and easy-going. you're extremly hot and passionate lover. you're loyal and honest and expect reciprocation from your lover.
You are a born leader, and have it in you how to tactfully derive work from people. People love the way you always treat them.
You love being loved, and when you receive your share of limelight from someone, you are all theirs.Repost This If It's True For You.!! 5 years of bad luck if you do not share this post.
******
If you are a CAT :
An extremely lovable, passionate, adorable person, sometimes shy, with a passion for quick wit.
At times, you prefer quietness. You love exploring various things and going into depth of each thing. you love being honest and loyal and expect reciprocation from your lover. you're full of energy in whole life.
Under normal circumstances you're cool but when given a reason to, you are like a volcano waiting to erupt. You're a fashion bird.
People look forward to you as an icon associated with fashion. Basically, you mingle along freely but don't like talking much to strangers.
People feel very easy in your company.
You observe care in choosing your friends.
Repost This If It's True For You.!! 2 years of bad luck if you do not share this post.
*****
If you are a TURTLE :
You are near to perfect and nice at heart.
The examples of your kindness are always circulated in groups of people. You too love peace. You wouldn't like to retaliate even to a person who is in the wrong. You are loved due to this.
You do not wish to talk behind one's back.
People love the way you always treat them.
You
here is nice post on this question
- Jack December 10, 2014campuscoke.blogspot.in/2014/12/explain-n-n-1-0.html