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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:22:39+00:00 2026-06-05T16:22:39+00:00

By using filestreaming in c++, I have read a string in the binary file

  • 0

By using filestreaming in c++, I have read a string in the binary file into a buffer (4 bytes). I know that the buffer contains “89abcdef“. The buffer is such that:

buffer[0] = 89
buffer[1] = ab
buffer[2] = cd
buffer[3] = ef

Now, I want to recover these numbers into one single hex number 0x89abcdef. However, this is not as simple as I thought. I tried the following code:

int num = 0;
num |= buffer[0];
num <<= 24;
cout << num << endl;

at this point, num is displayed to be

ea000000

When I tried the same algorithm for the second element of the buffer:

num = 0;
num |= buffer[1];
num <<= 16;
cout << num << endl;

output:

ffcd0000

The ff in front of the cd is highly inconvenient for me to add them all together (I was planning to make it something looks like 00cd0000, and add it to the first num).

Could anyone help me to recover the hex number 0x89abcdef? 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-05T16:22:42+00:00Added an answer on June 5, 2026 at 4:22 pm

    Don’t modify the actual number until the end:

    num = buffer [0] << 24 | buffer [1] << 16 | buffer [2] << 8 | buffer [3];
    

    buffer [0] << 24 gives you your first result, which is combined with the second result independent of the first, and so on.

    Also, as pointed out, operations like this should be done on unsigned numbers, so that the signing doesn’t interfere with the result.

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

Sidebar

Related Questions

Using the HTML5 File API I can get the Binary String representation of a
Using CRM 4, I have an entity form that contains a tab with an
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using VBA. My script moves a file into a directory. If that filename already
I have a SQL Server 2008 database with a table that contains a FILESTREAM
Using Java,I have to fetch multiple sets of values from an XML file to
Using report builder 3.0, I have a report that queries a cube. How do
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using Android 2.1+. I have a service that gets killed from time to time
Using Rails 3.1. I have some pages that render same layout, except the contents

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.