CareerCup Interview Question for Developer Program Engineers


Country: India




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

It all depends on whether you count the bits from the left or from the right and whether you start counting with 0 or 1.

- eugene.yarovoi February 20, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 vote

Use (i-1) instead of i that should get u a correct answer...

- Dev February 20, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This should do.

boolean getBit(int num, int i)
{
if ((num&(1<<(i-1)))!=0) return 1 ;
else 0 ;
}

- Vijay Rajanna February 20, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

If the number is 10, for the pos 2, we will get 1 as bit as per abv logic. Which is a wrong answer

- Anonymous February 20, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

The program still works fine.. For number 10 and pos 2.. The answer should be 1.

1010
0010
______
0010 != 0 hence return 1

- Vijay Rajanna February 20, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

/*
* In general, a 32 bit register has the following bits: {31, 30,...,i,..., 1, 0}.
* where i is zero based.
*
* If passing -O3 or -Os to ARM gcc,
* both solutions will generate the same ARM asm code.
* r0: num
* r1: i
* lsr.w r0, r0, r1
* and.w r0,r0,#1
* bx lr
*/
uint32_t getBit(uint32_t regValue, int i)
{
return (regValue >> i) & 1;
}

- shengliang.song November 11, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

It works but currently it returns only if bit is 1

- Anonymous December 16, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

It works but currently it returns only if bit is 1

- Anonymous December 16, 2014 | Flag Reply


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