Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7576039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:49:39+00:00 2026-05-30T16:49:39+00:00

I want to ask two C++ bitset questions. (1) How to create a bitset

  • 0

I want to ask two C++ bitset questions.

(1) How to create a bitset with a specified length from a function argument? I mean, for example, I have a function

void f(int n)

And inside f, I need to create bitset<n> bs; Is this something doable?

(2) How to copy part of a bitset bs to form a new bitset? For example, given starting index i1 and ending index i2 where i1>=i2, I need to form a new bitset by copying those bits in bs from the least i2th significant bit exclusive to the least i1th significant bit inclusive (just to conform with STL convention).

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T16:49:40+00:00Added an answer on May 30, 2026 at 4:49 pm

    (1) Not doable with std::bitset, because the size needs to be a compile-time constant (integral constant expression). You can use boost::dynamic_bitset, or, alternatively, std::vector<bool> or std::vector<char>

    (2) std::bitset does not a special constructor for what you’re looking for. You will need to write an explicit loop. All the other options listed in (1), however, have a constructor taking two iterators.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just want to ask how to merge two tables. Because I have a
i want to ask, what is the meaning or difference between these two line?
I want to ask if I should include the function that I am testing
I want to ask an NSString * question. I have a NSString * object.
I have one Sell Operation object and two Buy Operation objects, i want to
I have two C++ files, say file1.cpp and file2.cpp as //file1.cpp #include<cstdio> void fun(int
For example, you want to reverse a string, will there two ways: first: String
hi every one i want to ask that i want to compare two time
Hello,I'd like to ask you two questions. (I am using java and jedis) I
I want to ask some simple but important questions regarding iPhone development. If we

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.