Results 1 to 2 of 2

Thread: [C++] Creating a boost::dynamic_bitset from arbitrary raw data

  1. #1
    Join Date
    Mar 2006
    Beans
    837

    [C++] Creating a boost::dynamic_bitset from arbitrary raw data

    I want to know if there is more "official" or efficient way to create a dynamic_bitset from any raw data. I am not good with template code, but as far as I can tell there isn't class constructor for my use case. So I have written this piece of code:

    PHP Code:
    .....
      
    unsigned int length(ehave->string_length());
      
    char const* first ehave->string_ptr();

      
    boost::dynamic_bitset<> array(length*8);

      for (
    unsigned int i=0i<lengthi++)
      {
        
    char const* byte first+i;

        for (
    unsigned int a=0a<8a++)
          array[
    i*8] = (*byte & (1<<(a)));
      }
    ..... 
    What do you think? How do you do it?

  2. #2
    Join Date
    Mar 2006
    Beans
    837

    Re: [C++] Creating a boost::dynamic_bitset from arbitrary raw data

    And as I said I am not good with reading template code. After some more searching, it seems that there is a suitable constructor:

    PHP Code:
    template <typename BlockInputIterator>
        
    dynamic_bitset(BlockInputIterator firstBlockInputIterator last,
                       const 
    Allocatoralloc Allocator()); 
    So all I have to do now is:

    PHP Code:
    ....
      
    unsigned int length(ehave->string_length());
      
    char const* first ehave->string_ptr();

      
    boost::dynamic_bitset<unsigned char> array(firstfirst+length);
    .... 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •