Bloomberg LP Interview Question for Financial Software Developers






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

void print_binary(unsigned n) {
if(n)
{
print_binary(n >> 1);
cout << (n%2) ;
}
}

- shoushou January 24, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Awesome answer

- kc February 16, 2010 | Flag
Comment hidden because of low score. Click to expand.
2
of 0 vote

I can do it in less lines. The binary value is printed from less-significant digit to the most significant
void print_binary(unsigned int n) {
for(;n;n>>=1)
putchar(n&1?'1':'0');
}

- Leon January 06, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is print from LSB. We should print from MSB.

- onion834 January 21, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

void print_float(float f)
{

char *p;

p = (char *)(&f);
int mask=128;

int counter =0;

while(counter<sizeof(float)){

for(int i=0;i<8;i++){
printf("%d",(*p&(mask>>i)?1:0));
}

p++;

printf(" ");

counter++;
}

printf("\n");

}

- DJ December 18, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void print_binary(unsigned n) {
do {
print(n%2);
n<<=1;
while (n);
}
}

- Anonymous December 20, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I'm afraid ur multiplying times two

- wihenao August 13, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

void print_binary(unsigned n) {
int count = 31;
char buf[32] = {0};
do {
buf[count--] = n%2 + '0';
n>>=1;
}
while (n);
printf("%s", &buf[count+1]);
}

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

Guys,what does mean "n>>1" , what the o/p?

- mary January 08, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

n>>2=n/2

- Anonymous May 29, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

right shift >> is implement dependent
One could use << instead
int mask = 1 << 31;

do
{
std::cout << ( (n&mask)?1:0 );
}while( n << 1);

- Handong January 25, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Looks like comparitively good solution

- Gireesh April 24, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Even if n == 0?

- Tim December 12, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

int n = 5 ;
do {
cout << n%2 ;
n >>=1;
} while (n);

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

a=num; b=0;
while(a){
b *= 10;
b += a%2;
a = a/2;
}

- neat February 28, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

unsigned int x = 19 ;
showbits( x) ;

- easy !! March 31, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Recursive Method--

static void binary(int _number) 
        {
            int remainder;
            if(_number <= 1)
            Console.Write(_number);
            if (_number != 1)
            {
                remainder = _number % 2;
                binary(_number >> 1);
                Console.Write(remainder);
            }
        }

- Anonymous June 23, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

here you can use
either

binary(_number >> 1);

or

binary(_number/n);

both will work

- Anonymous June 23, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

int main() {
	unsigned int a = 0xF0F0F0F0;
	int numbits = sizeof(unsigned int)*8;
	unsigned int mask= 1 << (numbits-1);
	for(int i = 0; i < numbits; i ++) {
		cout << ((a & mask) > 0); 
		a = a << 1;
	}
}

- ely February 06, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{
    int a = 6;
    for(int  i = 31;i>=0;i--)
         { 
             if(1<<i & a) printf("1"); else printf("0");
         }
}

- :P March 06, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int count = 0;
while(num > 0)
{
   count++;
   num = num>>1;
}
return count;

- Dee April 15, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <stdio.h>
int main()
{
int n, c, k;
printf("Enter an integer in decimal number system\n");
scanf("%d", &n);
printf("%d in binary number system is:\n", n);
for (c = 31; c >= 0; c--)
{k = n >> c;
if (k & 1)
printf("1");
else
printf("0");}
printf("\n");
return 0;}

- Abhijithdb9 December 15, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static String binaryRepresentation(int a){
		StringBuilder output=new StringBuilder();
		
		int bitChecker = 1; 
		for(int i=0;i<=31;i++){
			output.append((a&bitChecker)>0?1:0);
			bitChecker=bitChecker<<1;
		}
		return output.reverse().toString();
	}

We can even use Integer.toBinaryString(a); directly if you would like to use in java

- Pavanraj April 11, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/*Recursive print*/
int printBin(int number)
{
        int bit;
        if(!number) return ;
        bit=number & 1;
        number=number>>1;
        printBin(number);
        printf("%d",(bit));

}

- Giri April 12, 2018 | 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