[algogeeks] 1's counting

2010-08-04 Thread amit
(3*4096+15*256+3*16+3). How many 1's are there in the binary
representation of the result.

Is there a quick way to count the number of set bits in this number
manually???

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] 1's counting

2010-08-04 Thread Seçkin Can Şahin
either count it with a for loop or if you are using C, use
__builtin_popcount(int x)

or

x is given
int count = 0;
for(int i=0; i32;i++) count += (x  (1i)) != 0;

On Tue, Aug 3, 2010 at 12:04 PM, amit amitjaspal...@gmail.com wrote:

 (3*4096+15*256+3*16+3). How many 1's are there in the binary
 representation of the result.

 Is there a quick way to count the number of set bits in this number
 manually???

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] 1's counting

2010-08-04 Thread jalaj jaiswal
it is
3*2^12 + 15*2^8 + 3*2^4 + 3
so it becomes
312 + 158 + 34 +3.. let this equal to n
take a int count=0;
while(n){
 n=n(n-1);
 count++;
}
return count;


2010/8/4 Seçkin Can Şahin seckincansa...@gmail.com

 either count it with a for loop or if you are using C, use
 __builtin_popcount(int x)

 or

 x is given
 int count = 0;
 for(int i=0; i32;i++) count += (x  (1i)) != 0;


 On Tue, Aug 3, 2010 at 12:04 PM, amit amitjaspal...@gmail.com wrote:

 (3*4096+15*256+3*16+3). How many 1's are there in the binary
 representation of the result.

 Is there a quick way to count the number of set bits in this number
 manually???

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
With Regards,
Jalaj Jaiswal
+919026283397
B.TECH IT
IIIT ALLAHABAD

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] 1's counting

2010-08-04 Thread jalaj jaiswal
it is
3*2^12 + 15*2^8 + 3*2^4 + 3
so it becomes
312 + 158 + 34 +3.. let this equal to n
take
while(n){


2010/8/4 Seçkin Can Şahin seckincansa...@gmail.com

 either count it with a for loop or if you are using C, use
 __builtin_popcount(int x)

 or

 x is given
 int count = 0;
 for(int i=0; i32;i++) count += (x  (1i)) != 0;


 On Tue, Aug 3, 2010 at 12:04 PM, amit amitjaspal...@gmail.com wrote:

 (3*4096+15*256+3*16+3). How many 1's are there in the binary
 representation of the result.

 Is there a quick way to count the number of set bits in this number
 manually???

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
With Regards,
Jalaj Jaiswal
+919026283397
B.TECH IT
IIIT ALLAHABAD

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] 1's counting

2010-08-04 Thread Bhanu Pratap Singh
Hi Amit,

If you are answer this question orally then the format you have given is
just a hexadecimal number. Its value would be 0x3f33. So the number of
1's would be simply 2+4+2+2 = 10.
Programatically whatever solution Sahin has given seems to be good enough.

2010/8/4 Seçkin Can Şahin seckincansa...@gmail.com

 either count it with a for loop or if you are using C, use
 __builtin_popcount(int x)

 or

 x is given
 int count = 0;
 for(int i=0; i32;i++) count += (x  (1i)) != 0;


 On Tue, Aug 3, 2010 at 12:04 PM, amit amitjaspal...@gmail.com wrote:

 (3*4096+15*256+3*16+3). How many 1's are there in the binary
 representation of the result.

 Is there a quick way to count the number of set bits in this number
 manually???

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
Regards
Bhanu
Mobile   +91 9886738496

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.