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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:36:48+00:00 2026-05-26T18:36:48+00:00

I have a an issue where I can’t serialize a 64bit integer (32bit works)

  • 0

I have a an issue where I can’t serialize a 64bit integer (32bit works)

Code is as follows:

uint64_t t = (uint64_t) 0;
uint8_t buffer[8];

buffer[0] = 0x12;
buffer[1] = 0x34;
buffer[2] = 0x56;
buffer[3] = 0x78;
buffer[4] = 0x9A;
buffer[5] = 0xBC;
buffer[6] = 0xDE;
buffer[7] = 0xF0;

printf("uint64_t width: %lu\n",sizeof(t));

t |= (uint64_t) ( (buffer[7] << (7*8))    & 0xFF00000000000000 );
t |= (uint64_t) ( (buffer[6] << (6*8))    & 0x00FF000000000000 );
t |= (uint64_t) ( (buffer[5] << (5*8))    & 0x0000FF0000000000 );
t |= (uint64_t) ( (buffer[4] << (4*8))    & 0x000000FF00000000 );
t |= (uint64_t) ( (buffer[3] << (3*8))    & 0x00000000FF000000 );
t |= (uint64_t) ( (buffer[2] << (2*8))    & 0x0000000000FF0000 );
t |= (uint64_t) ( (buffer[1] << (1*8))    & 0x000000000000FF00 );
t |= (uint64_t) ( (buffer[0])             & 0x00000000000000FF );

printf("uint64 value: 0x%llu\n",t);

however the compiler is warning me I have bit-shifted too far for the upper 32 bits. The sizeof operator is telling me its 64bit width though?

output is:

uint64_t width: 8
uint64 value: 0x78563412

Whats going on here?

  • 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-26T18:36:48+00:00Added an answer on May 26, 2026 at 6:36 pm

    You need to cast before you shift, e.g.

    t |= ((uint64_t)buffer[7] << (7*8)) & 0xFF00000000000000LLU;
    

    Actually you don’t even need the mask so this could just be simplified to:

    t |= (uint64_t)buffer[7] << (7*8);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this exact issue ASP.net can’t update page from event handler and it's
Can anyone help? I have an issue with calling a asp.net webservice from jquery..
can anyone help? I have an issue with linq2sql and trying to Attach (update)
I have a rather annoying issue here I can't get my CheckBox CheckedChange event
can anyone help, i have a small issue, i have an interface and also
Having an issue here that I have tried everything I can think of but
Contributing to open source can have many forms: working with issue trackers, patches, further
I have an nHibernate query issue that looks quite straight forward, but I can't
can you please help me with this issue the String class does not have
I have an issue I can't seem to figure out... I have a widget

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.