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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:50:33+00:00 2026-05-22T17:50:33+00:00

i dont understand why the output of both functions are getting nulled when i

  • 0

i dont understand why the output of both functions are getting nulled when i output them:

class uint128_t{

private:
    uint64_t UPPER, LOWER;

public:
    // constructors
    uint128_t(){
        UPPER = 0;
        LOWER = 0;
    }

    template <typename T>
    uint128_t(T rhs){
        UPPER = 0;
        LOWER = (uint64_t) rhs;
    }

    template <typename S, typename T>
    uint128_t(const S upper_rhs, const T lower_rhs){
        UPPER = (uint64_t) upper_rhs;
        LOWER = (uint64_t) lower_rhs;
    }

    uint128_t(const uint128_t & rhs){
        UPPER = rhs.UPPER;
        LOWER = rhs.LOWER;
    }

    //  RHS input args only

    // assignment operator
    template <typename T> uint128_t & operator=(T rhs){
        UPPER = 0;
        LOWER = (uint64_t) rhs;
        return *this;
    }

    uint128_t & operator=(uint128_t & rhs){
        UPPER = rhs.UPPER;
        LOWER = rhs.LOWER;
        return *this;
    }


    uint128_t operator<<(int shift){
        if (shift >= 128)
            return uint128_t(0, 0);
        else if (shift == 64)
            return uint128_t(LOWER, 0);
        else if (shift < 64)
            return uint128_t((UPPER << shift) + (LOWER >> (64 - shift)), LOWER << shift);
        else if ((128 > shift) && (shift > 64)){
            uint128_t a =uint128_t(LOWER << (shift - 64), 0);
            // a will show the correct values 
            std::cout << a.upper() << " " << a.lower() << std::endl;
            return uint128_t(LOWER << (shift - 64), 0);
            // in the program that includes this, printing out the values show 0 0
        }
    }

    uint128_t operator>>(int shift){
        if (shift >= 128)
            return uint128_t(0, 0);
        else if (shift == 64)
            return uint128_t(0, UPPER);
        else if (shift <= 64)
            return uint128_t(UPPER >> shift , ((UPPER << (64 - shift))) + (LOWER >> shift));
        else if ((128 > shift) && (shift > 64))
            return uint128_t(0, (UPPER >> (shift - 64)));
    }

    uint128_t operator<<=(int shift){
        *this = *this << shift;
        return *this;
    }

    uint128_t operator>>=(int shift){
        *this = *this >> shift;
        return *this;
    }

    const uint64_t upper() const {
        return UPPER;
    }

    const uint64_t lower() const {
        return LOWER;
    }

// lots of other stuff

};

int main(){

    uint128_t a(0x123456789abcdef1ULL, 0x123456789abcdef1ULL);

    a>>= 127; // or a <<= 127;
    std::cout <<a.upper() << " " <<a.lower() << std::endl;
    return 0;
}

http://ideone.com/jnZI9

can anyone figure out why?

  • 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-22T17:50:34+00:00Added an answer on May 22, 2026 at 5:50 pm

    Your int is 128 bits, you are shifting it down (right) 127 bits which means the upper most bit will be moved to the lower most position, and all other bits will be 0.

    But the int in your example is 0x1...., 0x1 (the highest nibble) is 0001 in binary, which does not have the upper bit set. So 0 is the correct output.

    If you change the 0x1... to an 0x8... (or anything higher than 0x7) you will most likely see 0…1 in the output.

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

Sidebar

Related Questions

i dont understand the problem with returning multiple rows: here is my table BBC:
I dont understand what would be the problem with the following code. It needs
according to this code i dont understand about NSClassFromString how did i know viewControllerName
I'm trying to understand the basic MVVM design approach, but I dont' understand where
I want to use the status method but i dont understand how it works.
This code works, but i dont understand why. With DeferredLoadingEnabld = false, I would
I am looking into authenticating via google. I dont understand how it works: http://code.google.com/apis/accounts/docs/OpenID.html#Samples
Im using Doctrine and i dont quite understand this code here: $this->hasColumn('id', 'integer', 8,
I have an issue with co/contra-variance. I understand you can't have both input and
See the code, then you would understand what I'm confused. Test.h class Test {

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.