ThoughtWorks Interview Question for Consultants






Comment hidden because of low score. Click to expand.
2
of 2 vote

Looks like a code for a timer to me.
Function waits until the bth bit of a is zero.
a might be an address of program status word or an i/o device address which keeps changing value. If such is true, a should've been defined as volatile.

- swap1712 July 25, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This piece of code is used to check "If the bth bit is set or not"

- Dilip September 28, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

There is no return from the function, neither any change in the value for a and b
Therefore this function is useless.

- DashDash September 28, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

It is loop waiting for a's bth bit. Note that a is a pointer.

- Eric Xu September 28, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think, Eric Xu is right... It makes sense in multi threading environment.

- Arang September 29, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

If bth bit is set it goes in infinite loop else it stops. The function does nothing. It returns nothing. Even value of *a does not get changed.

Maybe is used to check for bth bit and works as a wait loop(based on bth bit) before a mutex...where *a gets changed in some other process.

- sweetest September 28, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

No, If bth bit is set then we hav 1==0 which is false hence loop breaks

- cirus October 03, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

code works to check whether 10^b or 2^b == *a
if true then it breaks otherwise goes into infinite loop.

- Anonymous November 24, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

plz chk my solution.....if have drawn a picture to explain.....excuse for free hand....

- Sukhwinder singh (AIT) August 24, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

it is used to check the validity of input passed to the function.

- saurabh September 13, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This code checks, whether pointer to 'a' is 'b' th power of 2, or not.

- Kishore Debnath January 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

It is a useless Code.

- Chetna July 25, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

taking a few binary examples , i guess the code checks if b == a ; since if b equals a , the left shifting and and operation leads to zero as an answer and this takes us to an infinite loop ! but if b !=a the program may continue with execution .

- Novice Programmer August 01, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

to Know the position of first set bit....i.e. to know the place of 1st occurance of 1
ex:1100==>ans 3
ex:1000==>ans 4

- TJ Waseem Ur Rahman March 21, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

to find whether *a is 2 to the power of sth?

- KW September 28, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

gud

- Anonymous April 03, 2014 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More