bitset 
Author Message
 bitset

Hi All

I have several (approx. 100) bitset's with a length of 700
bits per bitset. What is the most efficient way of filling
these bitset's with random 1's and 0's.

Cheers for any help

Tad



Wed, 20 Jul 2005 18:47:14 GMT  
 bitset

--------------------

Quote:
> Content-Class: urn:content-classes:message


> Subject: bitset
> Date: Sat, 1 Feb 2003 02:47:14 -0800
> Lines: 9

> MIME-Version: 1.0
> Content-Type: text/plain;
>    charset="iso-8859-1"
> Content-Transfer-Encoding: 7bit
> X-Newsreader: Microsoft CDO for Windows 2000
> X-MIMEOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
> Thread-Index: AcLJ30gYr+7vKLtZSOS7kv8+5Uu3nQ==
> Newsgroups: microsoft.public.vc.language
> Path: cpmsftngxa06
> Xref: cpmsftngxa06 microsoft.public.vc.language:182391
> NNTP-Posting-Host: TK2MSFTNGXA04 10.40.1.52
> X-Tomcat-NG: microsoft.public.vc.language

> Hi All

> I have several (approx. 100) bitset's with a length of 700
> bits per bitset. What is the most efficient way of filling
> these bitset's with random 1's and 0's.

> Cheers for any help

> Tad

I would divide the number of bits to be filled in by 32 (number of bits in
an integer) (get the number of whole integers that you need). Get a pointer
to the first byte (hopefuly you have designed this so that the first bit is
the first bit in a byte with 4 byte alignment), cast this pointer to UINT
*. Then in a loop, use a random number generator to generate random
integers from 0 to UINT_MAX and write the UINT generated by the random
number generator to it and finally ++ the pointer for the next loop
iteration. Repeat this loop for the number of ints you need. Then fill in
the remaining bits that dont divide by 32.
A sample code like below might be OK (you need to add more tests and make
sure that your bitfields are 4 byte alligned though).

struct X {
    bit_t   b[700];

Quote:
};

void func(UINT *pLoc, int nIntegers) {
    for (int i = 0; i < nIntegers; i++) {
        UINT ui = ............; // Some random number generator
        *pLoc = ui;
        pLoc++;
    }

Quote:
}

void main() {
    X x;
    ...
    ...
    UINT *pLoc = .......;         // Get the address of the first byte in
the bit field x.b
    int nIntegers = 700/32;
    int nRemainder = 700 - nIntegers * 32;
    func(pLoc, nIntegers);

    // Here add code to do the random init for nRemainder number of bits
    ....
    ....

Quote:
}

--
Ameya Limaye, Liu Xiong, Visual C++ Team
This posting is provided AS IS with no warranties, and confers no rights.


Sun, 31 Jul 2005 03:44:24 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Bitset examples from the FAQ (unsigned char?)

2. libclc bitset import/export

3. libclc: bitset interface, new final vote

4. libclc: bitset interface

5. Help in finding the bitsets?

6. C++ to C# std::bitset

7. BITSET

8. bitsets

9. bitset?

10. template-Klasse bitset

11. use bitset instead

12. Compiler Error C2783 when using Bitsets.

 

 
Powered by phpBB® Forum Software