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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:27:51+00:00 2026-06-13T06:27:51+00:00

If I have a uint64_t original and two regular four byte ints, (which are

  • 0

If I have a uint64_t original and two regular four byte ints, (which are signed), I would like to store the value in the two ints and recover the unsigned 64 byte later. This should be possible because we have 64 bits available in both cases. I was thinking something along the lines of:

uint64_t test = 1350640807215539000;
int a = test >> 32; //get top 32 bits
int b = test & 0x00000000FFFFFFFF; //keep bottom 32 bits

uint64_t recover_test = ((a << 32) & b);

but this isn’t giving me back the original value of test…what part am I doing wrong?

  • 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-13T06:27:53+00:00Added an answer on June 13, 2026 at 6:27 am

    Instead of doing a lot of error-prone bit-twiddling you could just use a union:

    union
    {
        uint64_t u64;
        int32_t s32[2];
    } u;
    
    u.u64 = 1350640807215539000ULL;
    
    printf("a = %d\n", u.s32[0]);
    printf("b = %d\n", u.s32[1]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
I have a function which writes a 32-bit value to a buffer, and a
I have a variable declared as: enum class FooEnum: uint64_t {} and I would
I have a value like this: int64_t s_val = SOME_SIGNED_VALUE; How can I get
I have two projects in my solution; one which builds a static lib, another
For example, if I have a 64-bit variable and store two 32-bit items of
I have a template class which looks like the following: template <template <class TypeT>
I would like to have a user-defined key in a C++ std::map . The
I have this code in C (it's for study only): char x; uint64_t total
Why does: const char example; (uint64*)example have a value of 140734799798420 and *(uint64*)example have

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.