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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:01:12+00:00 2026-06-13T19:01:12+00:00

So I have 3 numbers. One is a char , and the other two

  • 0

So I have 3 numbers. One is a char, and the other two are int16_t (also known as shorts, but according to a table I found shorts won’t reliably be 16 bits).

I’d like to concatenate them together. So say that the values of them were:

10010001

1111111111111101

1001011010110101

I’d like to end up with a long long containing:

1001000111111111111111011001011010110101000000000000000000000000

Using some solutions I’ve found online, I came up with this:

long long result;
result = num1;
result = (result << 8) | num2;
result = (result << 24) | num3;

But it doesn’t work; it gives me very odd numbers when it’s decoded.

In case there’s a problem with my decoding code, here it is:

char num1 = num & 0xff;
int16_t num2 = num << 8 & 0xffff;
int16_t num3 = num << 24 & 0xffff;

What’s going on here? I suspect it has to do with the size of a long long, but I can’t quite wrap my head around it and I want room for more numbers in it later.

  • 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-13T19:01:13+00:00Added an answer on June 13, 2026 at 7:01 pm

    To get the correct bit-pattern as you requested, you shoud use:

    result = num1;
    result = (result << 16) | num2;
    result = (result << 16) | num3; 
    result<<=24;
    

    This will yield the exact bit pattern that you requested, 24 bits at the lsb-end left 0:

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

Sidebar

Related Questions

I have two NSMutabeArrays, one full of numbers, the other full of words. Lets
I have two arrays, the first one contents numbers and the second one use
I have a TABLE elements with one COLUMN number, type SMALLINT that contains numbers
I have an excel file, validating one column to enter numbers only but it
I have two forms. First one is to decide button numbers by using jslider.
I have a query that joins two tables. One table has a column that
I have one collection numbers with 200000 document object with {number: i} i =
If one calculates the recommendations for a boolean DataModel, the RecommendedItems have some numbers
If I have a list of numbers like this one: 10,9,8,8,9,7,6,5,4,6,7,8,11,10,12,14,16,20,30,29,28,29,27,25,20,18,15,10,8,5,4,1 I want to
I have a text file that has item numbers in it (one per line).

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.