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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:49:43+00:00 2026-06-15T07:49:43+00:00

I have another late night brain-dead question. It’s probably simple to do but you

  • 0

I have another late night brain-dead question. It’s probably simple to do but you know how it is after 8 hours+ of programming then reaching then end of a deadline. 🙂

Here is my question..

I have a boolean array of length 10 which is logically divided into seperate pieces to hold 4 different integer bit arrays (as booleans). Here is the target array:

bool[] myArray = new bool[10]; 

And here are the 4 integers I would like to insert:

int value1 = 3;  // 2 bits, myArray[0-1], 11
int value2 = 12; // 4 bits, myArray[2-5], 1100
int value3 = 2;  // 2 bits, myArray[6-7], 10
int value4 = 1;  // 2 bits, myArray[8-9], 01

myArray should end up looking like the following (note that the first element is position 0):

{(T,T),(T,T,F,F),(T,F),(F,T)}

Then ultimately what I want to do is convert myArray to an int value:

0x1111001001 = 969

Perhaps there is an even better way of doing this without having to use booleans? So let me rephrase my question in a more general sense:

How do I concatenate N int values into a target int?

Thanks!

  • 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-06-15T07:49:44+00:00Added an answer on June 15, 2026 at 7:49 am

    Normally, the common way to combine bits from several numbers into one is this (using your values and bitlengths as examples):

    var result = value1 | (value2 << 2) | (value3 << 6) | (value4 << 8);
    

    However, the number you printed at the end of your question has the numbers back to front. If that’s what you wanted, it’d be:

    var result = value4 | (value3 << 2) | (value2 << 4) | (value1 << 8);
    

    Of course this assumes that the code knows the desired bitlength of each value. If you don’t know the bitlength at compile-time, then you have to keep track of it at runtime, otherwise a single int like 1 won’t tell your code how many bits to use from it.

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

Sidebar

Related Questions

I have another simple question about Node. I'm trying to make a simple http
i have another (probably unanswered) question about map views. I have a map view
I have a simple address book type of database. I've probably overnormalised, but it's
Probably an ultra-stupid question, but it's late, i'm tired and dinners nearly ready.... Here's
I have another web app, that uses the liferay user database. But before a
I have another csv file where I am trying to do a simple word
i have another question on getting my XML serialization neat, which i can't seem
I have another question :(. I'm trying to download multiple files for my application.
Finally I'm transitioning to ARC. Sounds too late but all my projects have retrocompatiilty
I know this is a silly question and I feel so stupid , but

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.