NVIDIA Interview Question for Software Engineer / Developers






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

#define setbit(i,j,k) i=(k==0)?((1<<j)&i):((1<<j)|i)

- rampurearun September 16, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#define MACRO(i,j,k) i = i&(((((i>>j)<<1)|k)<<(j-1))|(~(1<<j)))

- Tulley February 26, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#define MACRO(i, j, k) i = ((((i >> j) & 1) ^ k) << j) ^ i

- drivehappy February 27, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is almost the best solution. Small correction as !k should be included.
#define MACRO(i, j, k) i = ((((i >> j) & 1) ^ !k) << j) ^ i

- gavinashg March 19, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

When jth bit is 0 and k=0 then i think your algo is not working...
ex- i=0x0000001A j=3rd bit k=0
check it

- Qurious October 25, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

When jth bit is 0 and k=0 then i think your algo is not working...
ex- i=0x0000001A j=3rd bit k=0
check it

- Qurious October 25, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

doesn't the question say hex number? won't it effect our code?

if not this will work - #define setbit(i,j,k) i=i^(k<<j)

- sai February 27, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

sorry, its
#define setbit(i,j,k) i=(i&(~(1<<j)))|(k<<j)

- sai February 27, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Is it correct :-

i = i | ( (1 << j) & (k << j));

- sandygupta February 28, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

i^(k<<j-1)

- rajat ahuja February 28, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

@sandy i guess no. because if i has 1 in the jth bit, k as 0, ( (1 << j) & (k << j)); of your code returns 0 but the '|' wont be able to set it. see the #define MACRO(i,j,k) i = ((i | (1 << j))&(k << j)) that codebuddy defined above.

- sai March 02, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

first set the j'th bit to 0, then add j'th bit to it.

#define MACRO(i,j,k) i = (i & (~(1<<j)) + (k<<j))

- pc March 05, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

To optimize:
#define MACRO(i,j,k) i = (i & (~(1<<j)) | (k<<j))

I realized, it is same as sai's macro.

- pc March 05, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#define SET(i,j,k) (i^(((i>>j&1)^k)<<j))

- simransraj July 31, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can some one explain the logic

- anon July 31, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#define REPLACE_BIT(i, j, k) ((k == 1) ? ((i) | (1 << j)) : ((i) & ~(1 << j)))

- Anonymous September 18, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

#define MACRO(i,j,k) i=i&((a<<j)&k))

- Anonymous February 26, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

#define MACRO(i,j,k) i=i&((1<<j)&k))

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

if k =0 then i will become 0 always.

- Tulley February 26, 2011 | Flag
Comment hidden because of low score. Click to expand.
-1
of 3 vote

#define MACRO(i,j,k) i = ((i | (1 << j))&(k << j))

- codebuddy February 26, 2011 | 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