NVIDIA Interview Question for Software Engineer / Developers






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

x = ((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1); //Only this line if 2 bits can represent the integer
x = ((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2); //This and all above if 4 (or less) bits can represent the integer
x = ((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4); //This and all above if 8 (or less) bits can represent the integer
x = ((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8); //This and all above if 16 (or less) bits can represent the integer
x = ((x & 0xffff0000) >> 16) | ((x & 0x0000ffff) << 16); //This and all above if 32 (or less) bits can represent the integer

So all above four lines can be used for any integer (32 bit integer)
For input 1001101 i.e. decimal 77, 1st three lines will give the result as input can be taken as 8 bits (01001101), so after 3rd line of execution, value of x will be:
10110010

- Anurag Singh January 27, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

you are partially right. the question is to reverse all bits in a string. String can be more than 32 bits. if say each character is 32 bits then reverse each character within itself first and then do the generic procedure to reverse a string with these reversed characters.

- Anonymous January 27, 2011 | Flag
Comment hidden because of low score. Click to expand.
2
of 2 vote

Previous two suggestions can be combined for use.
1) Reverse the long character string at byte level.
2) Then do the table look-up to reverse bits in every character of the reversed string.

- Anonymous June 03, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Question says: bitwise reverse a very long character string
If it is bytewise, then we may do following:
1.Scan string characters from both side (front and end) using two variable say i and j.
2.Swap str[i] and str[j]
3.increment i and decrement j
4.Repeat 2 and 3 until i>=j

for(i=0,j=strlen(str);i<j;i++,j--)
swap(str[i],str[j]);

I can't think of any better soln. Other ideas pls.

- Anurag Singh January 29, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

well, i looked all over the place and it seems when u want to reverse binary representations "efficiently", you generally do table lookups..

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

use a stack , push and then pop

- odie January 07, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

bitwise left-shift the bit stream and then bitwise right-shift the result

- r April 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1- reverse the string (byte level) e.g: "hello world" -> "dlrow olleh" i.e 0x64,0x6c etc
2 - bit-wise reverse every byte , 0x26,0x36 etc

- Rahul June 23, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

XOR with all zeros.

- rits January 15, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

sorry, wrong ans.

- rits January 15, 2011 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

XOR with the same string.

- sam January 17, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

for your kind information n^n = 0. this holds for all integers present in this universe

- CAFEBABE December 28, 2011 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

I think u r wrong..
XOR the String with all ones...
Let Give:101011100
XOR with 111111111
we get 010100011=~(givenstring)

- keshav January 18, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

The question is to reverse the string. i.e., 1001101 should result in 1011001. What you answered is complement of all bits.

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

it is good if been asked to solve another problem btw

- odie January 07, 2012 | Flag
Comment hidden because of low score. Click to expand.
-2
of 2 vote

The question is not to reverse the binary rep. string, but to reverse a string...i.e reversing a string doesnt result in bitwise reversing.....we have to do byte wise reversing........wht say?

- Juggernaut January 28, 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