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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:15:10+00:00 2026-05-28T01:15:10+00:00

I need to work with a large array of 26-bit variables in RAM. It

  • 0

I need to work with a large array of 26-bit variables in RAM. It is too expensive to use 32-bit ints. Access should be as fast as possible (especially read operation).

I came to the following scheme: each 26-bit value splits to three 8-bit values and one 2-bit value.

#define N 500000000
uint8 arr1[N], arr2[N], arr3[N];
uint8 arr4[N / 4];

int read_value(int index)
{
  int a1 = arr1[index];                                   // bits 0..7
  int a2 = arr2[index];                                   // bits 8..15
  int a3 = arr3[index];                                   // bits 16..23
  int a4 = (arr4[index / 4] >> (2 * (index % 4))) & 3;    // bits 24..25
  return a1 | (a2 << 8) | (a3 << 16) | (a4 << 24);
}

Is there some better technique to do this?
Or maybe there is a nice way to work with 27/28/29/30-bit integers?

  • 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-28T01:15:11+00:00Added an answer on May 28, 2026 at 1:15 am

    When you say it’s “too expensive” to use 32-bit ints, do you mean space-wise?

    Assuming that you do, I’m not really sure how to help you there. However, in terms of read speed, an array in C/C++ provides you constant-time access to the elements of the array(this is assuming that the memory is already in the CPU cache; if it isn’t, it’s going to take longer). Therefore, reading element 0 takes the same amount of time as reading element 10,000; the code that you have might make this slower, but I can’t say that for certain.

    While it looks like this code should do what you want to do, it would probably make the most sense to simply do an array of ints, even though it would take up more space. If you absolutely have to this, you could try putting inline in your method declaration so the compiler can expand it whenever you use it.

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

Sidebar

Related Questions

I need to work with array from several threads, so I use CRITICAL SECTION
I need to work with large files and must find differences between two. And
For some graphics work I need to read in a large amount of data
At work, we just got a large number exotic cellular devices that need to
I'm using Mathematica to work with a large array of website files, which I've
I have a large array (a few hundred objects), and I need to separate
Background: I have a large 2D array of integers that I need to load
I need to work with MSMQ (Microsoft Message Queuing). What is it, what is
I need to work with some old C++ code that was developed in Visual
I need to work with a third-party Java library from .NET. Can anyone recommend

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.