Bit Manipulation Interview Questions
- 3of 3 votes
AnswersGiven pointer to the bytes array on size N that represents big integer "a" and 2-bytes integer "b" implement mod (%) operation for them: a % b
- russ.kovich December 14, 2012 in United States for Bing| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Bit Manipulation - -1of 3 votes
AnswersGiven a number x = 0x25. Convert it into y = 0x25252525.
- Nitin Gupta November 03, 2012 in India| Report Duplicate | Flag | PURGE
Adobe Member Technical Staff Algorithm Bit Manipulation C Coding - 0of 0 votes
AnswersWrite a program to swap odd and even bits of a 32-bit unsigned integer with as few instructions as possible. (bit-0 and bit-1 are swapped, bit-2 and bit-3 are swapped and so on)
- @ce October 24, 2012 in India| Report Duplicate | Flag | PURGE
Microsoft Intern Bit Manipulation - 0of 0 votes
AnswersAssuming you have three N bit unsigned integers a, b and c, what is the min number of bits you would need to store the result of a * b + c?
- ANKSCIRCLE October 20, 2012 in United States| Report Duplicate | Flag | PURGE
NVIDIA Software Engineer / Developer Bit Manipulation - 0of 2 votes
AnswersGiven a file of N bytes. Find a sub-string of minimal length that is not present in the file.
- Amarantine September 21, 2012 in Russia| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Bit Manipulation - 1of 1 vote
AnswersDetermine efficiently if an integer is a power of 2 without using any branching or loop.
- ashok.singh.sairam September 10, 2012 in India| Report Duplicate | Flag | PURGE
Cognzant Technology Solutions Software Engineer / Developer Bit Manipulation - 0of 0 votes
AnswersFind the maximum and minimum of two integers without use branching (i.e. without using any conditional statements like if if else etc)
- ashok.singh.sairam September 10, 2012 in India| Report Duplicate | Flag | PURGE
Cognzant Technology Solutions Software Engineer / Developer Bit Manipulation - 0of 0 votes
Answersswap every two bits in an unsigned char .. eg swap bits at 0 and 1st position, swap 2nd and 3rd position, swap 4th and 5th position etc ..
- dvyas May 16, 2012 in United States| Report Duplicate | Flag | PURGE
NVIDIA Software Engineer / Developer Bit Manipulation - 1of 1 vote
AnswersGiven two numbers "a" and "b" and an average formula (a+b)/2. Find one condition where it wont work. Also, give solution to it
- dvyas May 16, 2012 in United States| Report Duplicate | Flag | PURGE
NVIDIA Software Engineer / Developer Bit Manipulation C - 2of 2 votes
Answersgiven two integers and two bit positions. Set the first integer between the two bit positions to be that of the second integer.
- Lively May 06, 2012 in United States| Report Duplicate | Flag | PURGE
NVIDIA Software Engineer / Developer Bit Manipulation - 2of 2 votes
AnswersGiven a function, take a number and the bit position and return true if that bit is set to 1 and false otherwise.
- An April 04, 2012 in United States
It took me a few minutes to think something like this, pasted code is after he corrected me on 2 silly mistakes.
bool ret_result(int number, int pos) {
int k=1;
for(int i=0;i<pos;i++) {
k=k<<1;
}
if(number&k==1) {
return true;
}
else {
return false;
}
}| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Bit Manipulation - 2of 2 votes
AnswersCalculate number of zeros in a given integer.
- test222 March 29, 2012 in United States| Report Duplicate | Flag | PURGE
Amazon Intern Bit Manipulation - -1of 1 vote
AnswersIn the page 90 of Gayle's cracking the coding interview book, there was a method defined which is used to get the bit at particular position. Method goes like this...
- mooveprince February 20, 2012 in India
boolean getBit(int num, int i) {
return ((num&(1<<i))!=0);
}
Will this works..? if my number is 8 and I want to get the 3rd position, this return a wrong result| Report Duplicate | Flag | PURGE
CareerCup Developer Program Engineer Bit Manipulation - 1of 1 vote
AnswersWrite a function to convert an IPv4 Address in string format to an unsigned integer
- Fab February 10, 2012 in United States for Instant Video| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Bit Manipulation - 0of 0 votes
AnswersWrite a function that returns true if the bit stream has an alternating pattern. For example 000000101010 would return true and 0000001010000 would return false. Also I had to write test cases for the function.
- P.M January 24, 2012 in United States| Report Duplicate | Flag | PURGE
Bit Manipulation - 0of 0 votes
AnswersDesign a mask for the string M, which has to replace the bits of N at i th position. Given a the bit-length of sequence N as j. Design a function to return the masked data.
- einstein.goli October 25, 2011 in United States| Report Duplicate | Flag | PURGE
Qualcomm Software Engineer / Developer Bit Manipulation - 0of 0 votes
Answersfind the index of the highest bit set of a 32-bit number (without loops obviously)
- pavel.em October 18, 2011 in -| Report Duplicate | Flag | PURGE
Microsoft Bit Manipulation - 0of 0 votes
Answersgiven a 32-bit integer x
find the smallest integer x0 > x
with the same number of ones in binary representation
Example:x = 76 x0 = 81
solution without loops and additional storage ?
- pavel.em October 02, 2011 in -| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Bit Manipulation - 0of 0 votes
AnswersGiven two indices in a byte m and n such that m>=n extract all the bits between m and n in a single instruction.
- Sunil bn September 11, 2011 in India| Report Duplicate | Flag | PURGE
Ittiam Systems Software Engineer / Developer Bit Manipulation - 0of 0 votes
AnswersImplement a function that performs binary addition. Input to the function is two const strings. The function returns a string that holds the result of addition.
- Jobseeker August 24, 2011
char* binaryadd(const char* a, const char* b) { }
Eg. "1001"+"101"="1110"| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm Bit Manipulation C Coding String Manipulation - 0of 0 votes
AnswersYou are given two 32-bit numbers, N and M, and two bit positions, i and j. Write a method to set all bits between i and j in N equal to M (e.g., M becomes a substring of N located at i and starting at j).
- Algoseekar April 29, 2011
EXAMPLE:
Input: N = 10000000000, M = 10101, i = 2, j = 6
Output: N = 10001010100
_
________________________________________________________________| Report Duplicate | Flag | PURGE
Adobe Software Engineer / Developer Bit Manipulation - 1of 1 vote
AnswersRotation of a 32 bit number
- abcTemp March 18, 2011| Report Duplicate | Flag | PURGE
NVIDIA Software Engineer / Developer Bit Manipulation - 1of 1 vote
AnswersCount the no. of 1's in a 32 bit no. where there are mostly 0's in the number?
- NVIDIA reject March 15, 2011
Since the no. has less 1's. Dont itereate on any mask or temp. instead, do this,
if (num > 0)
{
if(num >> 2 & 1)
count ++;
number = number >> 2;
}
this would make the number diminish each time and give a optimal solution.| Report Duplicate | Flag | PURGE
NVIDIA Software Engineer / Developer Bit Manipulation C - 0of 0 votes
AnswersCode to find the MSB
- SK March 09, 2011| Report Duplicate | Flag | PURGE
NVIDIA Software Engineer / Developer Bit Manipulation