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

  • Home
  • SEARCH
  • 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 6860303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:23:31+00:00 2026-05-27T02:23:31+00:00

I should be able to store a value in a data structure that could

  • 0

I should be able to store a value in a data structure that could go from 0 to 3.. so I need 2 bits. This data structure I will be great 2 ^ 16 locations. So, i want to have 2 ^ 16 * 2 (bits). In C + + do you use to have exactly 2 bits in memory?

  • 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-27T02:23:32+00:00Added an answer on May 27, 2026 at 2:23 am

    You need two bits per unit (not three), so you can pack four units into one byte, or 16 units into one 32-bit integer.

    So you will need a std::array<uint32_t, 4096> to accomodate 216 units of 2-bit values.

    You access the nth value as follows:

    unsigned int get(std::size_t n, std::array<uint32_t, 4096> const & arr)
    {
        const uint32_t u = arr[n / 16];
        return (u >> (2 * (n % 16))) & 0x3;
    }
    

    Alternatively, you could go with a bitfield:

    struct BF32 {
      uint32_t u0 : 2;
      uint32_t u1 : 2;
      //...
      uint32_t uF : 2;
    }
    

    And then make an std::array<BF32, 4096>.

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

Sidebar

Related Questions

My project requires a file where I will store key/value pair data that should
I'm writing a little desktop app that should be able to encrypt a data
I need JavaScript working almost perfectly in my application that should be able to
I have a stored procedure that ideally should be able to accept a list/table
I'm writing a factory class that should be able to return singleton instances of
How do you deal with a DateTime that should be able to contain an
I would like to know what kind of data structure (queue) I should use
I'm looking for a data structure that has the following properties. Stores a list
I'm writing a data processing library in Python that reads data from a variety
I have set up a circular linked list data structure that represents a word,

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.