Re: Bits in integer-Wert

David Haller <[email protected]>
Newsgroups gmane.linux.suse.programming
Message-ID <[email protected]>
Hallo,

Am Tue, 05 Apr 2005, Marcel Reckers schrieb:
>Das ist aber ganz schön aufwendig, findest du nicht ?
>Nichts gegen das Programm, das funktioniert ja, aber es geht wirklich 
>kÃŒrzer und einfacher.

Das musst gerade du sagen.

Fuer C++ gibt es <bitset>.

==== UNGETESTET (nur teils aus dem Stroustrup abgeschrieben) ====
#include <bitset>
#include <iostream>

using namespace std;

#define N 32

int main(void) {
    bitset<N> b = 5; // oder bitset<N> b; cout << "zahl: "; cin >> b;
    int bitsset;
    for(register unsigned int i = 0; i < N; i++) {
        if( b[i] ) { bitsset++; }
    }
    cout << bitsset << endl;
    return 0;
}
====

<bitset> bietet diverse interessante Operationen an.

-dn'*GNA*'h

-- 
Auch wieder richtig, aber zum bloed posten brauch ich kein Hirn.
Ausserdem tipp ich schneller, als ich denke :).     -- Klaus Muth

-- 
Um die Liste abzubestellen, schicken Sie eine Mail an:
    [email protected]
Um eine Liste aller verfÃŒgbaren Kommandos zu bekommen, schicken
Sie eine Mail an: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.