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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:43:28+00:00 2026-05-21T07:43:28+00:00

I have some code I have in the Arduino environment that requires x (in

  • 0

I have some code I have in the Arduino environment that requires x (in increments of 8) boolean values that are manipulatable during run time for some shift register code. So currently I am using a boolean array like so:

 #define number_of_shiftRegisters 220 //num of 8 bit shift registers

 #define numOfRegisterPins number_of_shiftRegisters * 8 //number of booleans needed

 boolean registers[numOfRegisterPins]; //boolean array

But I was running out of RAM around 200 (1600 booleans) and didn’t know why until I saw that, even though booleans are 1 bit, they are stored in 8 bits of data.

As I said before, the number of bools needed is always in an increment of 8, so I don’t know if that could work to my advantage.

Is there a more memory efficient way to store 1000+ boolean values and still be able to reference them by index?

Or… At least more memory efficient that will not cost significantly more CPU time to set and iterate through?

I had thought about a char array, and then bit masking each char to access the individual bits. But I didn’t know if there was an easier way, or if this would take up considerably more CPU time.

  • 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-21T07:43:29+00:00Added an answer on May 21, 2026 at 7:43 am

    Yes, you could easily use masking to get around that issue..

    Every byte (unsigned char) will contain 8 boolean values, to get the i-th you can just use values & (1 << i) in if tests, and it will work since if the correct bit is set, then result will be != to 0.

    To set instead a bit just shift it and or to the value: values | (1 << i) (in case of unset you have to AND it with 0).

    Another solution could be to use a packed struct:

    struct Bools
    {
      int b1 : 1;
      int b2 : 1;
      int b3 : 1;
      ... // up to b8
    }
    

    This should manage elements with direct access to the boolean value and allow you to define an union to manage them either as 8 single bit booleans value either as bytes.

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

Sidebar

Related Questions

I have some code that sets up a dictionary with some defualt values for
I have some code that I want to run in a utility application whenever
I have some code using a System.Transactions.TransactionScope , that creating a new instance of
I have some code in Netbeans 6.1 editor that looks like this fooString(8) fooString(8)
I have some code using Lucene that leaves the default conjunction operator as OR,
I have some code I am working on that worked just fine until I
I have some code that gets the current logged in user. userID = request.session.get(_auth_user_id)
I have some code that is using SyncEnumerator. As you can see here ,
I have the following code on my Arduino that constantly checks for a serial
I have some code that can convert a single color in a template image

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.