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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:35:58+00:00 2026-06-10T09:35:58+00:00

In here When converting from bytes buffer back to unsigned long int: unsigned long

  • 0

In here
When converting from bytes buffer back to unsigned long int:

  unsigned long int anotherLongInt;

  anotherLongInt = ( (byteArray[0] << 24) 
                   + (byteArray[1] << 16) 
                   + (byteArray[2] << 8) 
                   + (byteArray[3] ) );

where byteArray is declared as unsigned char byteArray[4];

Question:

I thought byteArray[1] would be just one unsigned char (8 bit). When left-shifting by 16, wouldn’t that shift all the meaningful bits out and fill the entire byte with 0? Apparently it is not 8 bit. Perhaps it’s shifting the entire byteArray which is a consecutive 4 byte? But I don’t see how that works.

  • 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-10T09:35:59+00:00Added an answer on June 10, 2026 at 9:35 am

    In that arithmetic context byteArray[0] is promoted to either int or unsigned int, so the shift is legal and maybe even sensible (I like to deal only with unsigned types when doing bitwise stuff).

    6.5.7 Bitwise shift operators

    The integer promotions are performed on each of the operands. The type of the result is that of the promoted left operand.

    And integer promotions:

    6.3.1.1

    If an int can represent all values of the original type the value is converted to an int;
    otherwise, it is converted to an unsigned int. These are called the integer promotions.

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

Sidebar

Related Questions

Converting to ODB.NET from System.Data.OracleClient and need help converting my connection string. Here is
I'm converting an existing program to C++ and here need to manipulate Sybase timestamps.
I posted a question here concerning creating a shopping cart. It seems maybe I
I think my understanding of bytes arrays and char arrays is causing me some
I am having trouble converting an image into bytes and saving it in database.
I'm converting the following code from C# to C, and I don't think I'm
this is my first question, although I've already used so many tips from Stack
I need help converting this code from C# to Java. public static ulong GetChecksum(byte[]
I'm trying to get the HttpPost result from server and converting it into byte
Converting values read from proc/net/tcp6 0000000000000000FFFF00000100007F to ::ffff:10.200.0.31 I am familiar with converting ipv4

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.