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 6914303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:19:48+00:00 2026-05-27T09:19:48+00:00

I have an interesting little problem, and I know there are multiple ways to

  • 0

I have an interesting little problem, and I know there are multiple ways to skin the cat but I was wondering what would the best/most efficient way be.

Say for example I have an integer with the value 534 and an array that can store 16 booleans

now, 534 to binary is 10000010110

how would be the best way to get from 534 to

array[0] = 0
array[1] = 1
array[2] = 1
array[3] = 0
array[4] = 1
....
array[15] = 0

thanks in advance!

  • 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-27T09:19:49+00:00Added an answer on May 27, 2026 at 9:19 am

    Use std::bitset<16> and call operator[] to access individual bits:

    #include <iostream>
    #include <bitset>
    
    int main()
    {
         std::bitset<16> bits(534);
         std::cout << bits << std::endl;
    
         //use operator[] to access individual bits
         std::cout << bits[2] << std::endl; 
    }
    

    Output (demo):

    0000001000010110
    1
    

    This may not be most efficient but if you consider safety, then it is better alternative to raw array types. The efficiency difference will be almost negligible.

    If the number of bits is not known at compile time, and can be known at runtime, then boost::dynamic_bitset will help you. Have a look at it:

    • dynamic_bitset

    From its doc,

    The dynamic_bitset class represents a set of bits. It provides accesses to the value of individual bits via an operator[] and provides all of the bitwise operators that one can apply to builtin integers, such as operator& and operator<<. The number of bits in the set is specified at runtime via a parameter to the constructor of the dynamic_bitset.

    The dynamic_bitset class is nearly identical to the std::bitset class. The difference is that the size of the dynamic_bitset (the number of bits) is specified at run-time during the construction of a dynamic_bitset object, whereas the size of a std::bitset is specified at compile-time through an integer template parameter.

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

Sidebar

Related Questions

I have an interesting problem and would appreciate your thoughts for the best solution.
There is an interesting problem at hand. I have a role-playing MMOG running through
I have a little problem with jQuery UI 's droppable component, but I'm not
I have a interesting problem in Java, its a little wordy though so bear
Having an interesting little problem with my iPhone app. I have a view with
I have an interesting problem that I'm trying to solve and was wondering if
I have one interesting problem. I must parse mail body (regular expression), get some
I have an interesting query to do and am trying to find the best
I have some interesting problem for an hour.. In my flex project, all width
I have an interesting SQL problem that I need help with. Here is the

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.