Click here to Skip to main content
15,915,873 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Finding number of bits set in a given number Pin
Stephen Hewitt7-Mar-06 11:53
Stephen Hewitt7-Mar-06 11:53 
GeneralRe: Finding number of bits set in a given number Pin
BadKarma7-Mar-06 12:17
BadKarma7-Mar-06 12:17 
AnswerRe: Finding number of bits set in a given number Pin
Chris Losinger7-Mar-06 2:07
professionalChris Losinger7-Mar-06 2:07 
GeneralRe: Finding number of bits set in a given number Pin
toxcct7-Mar-06 2:25
toxcct7-Mar-06 2:25 
GeneralRe: Finding number of bits set in a given number Pin
Blake Miller7-Mar-06 3:23
Blake Miller7-Mar-06 3:23 
GeneralRe: Finding number of bits set in a given number Pin
toxcct7-Mar-06 3:27
toxcct7-Mar-06 3:27 
GeneralRe: Finding number of bits set in a given number Pin
BadKarma7-Mar-06 2:30
BadKarma7-Mar-06 2:30 
AnswerRe: Finding number of bits set in a given number Pin
Gary R. Wheeler7-Mar-06 2:51
Gary R. Wheeler7-Mar-06 2:51 
unsigned int sample; // value to count bits in
unsigned int count = ((sample >> 31) & 0x00000001) +
                     ((sample >> 30) & 0x00000001) +
                     ((sample >> 29) & 0x00000001) +
                     ((sample >> 28) & 0x00000001) +
                     ((sample >> 27) & 0x00000001) +
                     ((sample >> 26) & 0x00000001) +
                     ((sample >> 25) & 0x00000001) +
                     ((sample >> 24) & 0x00000001) +
                     ((sample >> 23) & 0x00000001) +
                     ((sample >> 22) & 0x00000001) +
                     ((sample >> 21) & 0x00000001) +
                     ((sample >> 20) & 0x00000001) +
                     ((sample >> 19) & 0x00000001) +
                     ((sample >> 18) & 0x00000001) +
                     ((sample >> 17) & 0x00000001) +
                     ((sample >> 16) & 0x00000001) +
                     ((sample >> 15) & 0x00000001) +
                     ((sample >> 14) & 0x00000001) +
                     ((sample >> 13) & 0x00000001) +
                     ((sample >> 12) & 0x00000001) +
                     ((sample >> 11) & 0x00000001) +
                     ((sample >> 10) & 0x00000001) +
                     ((sample >>  9) & 0x00000001) +
                     ((sample >>  8) & 0x00000001) +
                     ((sample >>  7) & 0x00000001) +
                     ((sample >>  6) & 0x00000001) +
                     ((sample >>  5) & 0x00000001) +
                     ((sample >>  4) & 0x00000001) +
                     ((sample >>  3) & 0x00000001) +
                     ((sample >>  2) & 0x00000001) +
                     ((sample >>  1) & 0x00000001) +
                     (sample         & 0x00000001);
Of course, this assumes that you know that an unsigned int occupies 32 bits.


Software Zen: delete this;
GeneralRe: Finding number of bits set in a given number Pin
toxcct7-Mar-06 2:53
toxcct7-Mar-06 2:53 
GeneralRe: Finding number of bits set in a given number Pin
Gary R. Wheeler7-Mar-06 2:59
Gary R. Wheeler7-Mar-06 2:59 
AnswerRe: Finding number of bits set in a given number Pin
BadKarma7-Mar-06 6:03
BadKarma7-Mar-06 6:03 
QuestionDirectShow SDK download Pin
Storm-blade7-Mar-06 0:03
professionalStorm-blade7-Mar-06 0:03 
AnswerRe: DirectShow SDK download Pin
Justin Tay7-Mar-06 5:26
Justin Tay7-Mar-06 5:26 
AnswerRe: question Pin
toxcct7-Mar-06 0:01
toxcct7-Mar-06 0:01 
QuestionUsing VC7.1 compiler under VC6 IDE.... woes.... :S Pin
kevingpo6-Mar-06 23:52
kevingpo6-Mar-06 23:52 
AnswerRe: Using VC7.1 compiler under VC6 IDE.... woes.... :S Pin
toxcct6-Mar-06 23:59
toxcct6-Mar-06 23:59 
GeneralRe: Using VC7.1 compiler under VC6 IDE.... woes.... :S Pin
kevingpo7-Mar-06 0:03
kevingpo7-Mar-06 0:03 
GeneralRe: Using VC7.1 compiler under VC6 IDE.... woes.... :S Pin
mkuhac7-Mar-06 2:01
mkuhac7-Mar-06 2:01 
AnswerRe: Using VC7.1 compiler under VC6 IDE.... woes.... :S Pin
Gary R. Wheeler7-Mar-06 2:55
Gary R. Wheeler7-Mar-06 2:55 
QuestionList View Multiple Selection Pin
Anil_vvs6-Mar-06 23:39
Anil_vvs6-Mar-06 23:39 
AnswerRe: List View Multiple Selection Pin
Nibu babu thomas6-Mar-06 23:47
Nibu babu thomas6-Mar-06 23:47 
AnswerRe: List View Multiple Selection Pin
Xing Chen7-Mar-06 16:14
Xing Chen7-Mar-06 16:14 
Questionread from physical memory Pin
ss20066-Mar-06 23:38
ss20066-Mar-06 23:38 
AnswerRe: read from physical memory Pin
fisp6-Mar-06 23:51
fisp6-Mar-06 23:51 
QuestionRe: read from physical memory Pin
David Crow7-Mar-06 3:49
David Crow7-Mar-06 3:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.