Microsoft Interview Question
1,049 Interview Reviews |
Back to all Microsoft Interview Questions & Reviews
Interview questions and reviews posted anonymously by interview candidates
Interview Question for Software Engineer at Microsoft:
Helpful Question?
Yes |
No
Inappropriate?
Answers & Comments (10)
int bits = 0;
for(int i = 0; i < sizeof(input); i++)
{
bits += (input >> i) & 0x01;
}
Helpful Answer?
Yes |
No
Inappropriate?
0 of 1 people found this helpful
byte input;
int count = 0;
while (input)
{
++count;
cout >> 1;
}
Helpful Answer?
Yes |
No
Inappropriate?
byte input;
int count = 0;
while (input)
{
++count;
input >> 1;
}
Helpful Answer?
Yes |
No
Inappropriate?
#include <stdio.h>
#include <limits.h>
int main()
{
printf("Number of bits per byte on this machine with this ANSI C compiler = %d\n", CHAR_BIT);
return 0;
}
Helpful Answer?
Yes |
No
Inappropriate?
i checked on google and the question is
Count the "on" bits in a byte?
Helpful Answer?
Yes |
No
Inappropriate?
char c;
int bits=0;
for (int i=0;i<8;i++)
{
bits+=c & 00000001;
c>>1;
}
return bits
Helpful Answer?
Yes |
No
Inappropriate?
1 of 1 people found this helpful
while (x != 0)
{
x = x& (x-1)
count++;
}
Helpful Answer?
Yes |
No
Inappropriate?
{
count += (number & 0x01);
number >>= 1;
}
Helpful Answer?
Yes |
No
Inappropriate?
num&num-1 should work
Helpful Answer?
Yes |
No
Inappropriate?
Members can
answer or comment on this question
–
Join Now (It's Free) or
Sign In



0 of 1 people found this helpful
by JB: