Thread: Just a quick one - getting unexpected result for bitwise AND

  1. #1
    Registered User
    Join Date
    Jun 2013
    Posts
    27

    Just a quick one - getting unexpected result for bitwise AND

    My code:

    Code:
    Primitive<uint64_t> full = 0xBBBBBBBBCCCCCCCC;
    Primitive<uint64_t> first = 0x0000000000000000;
    first = (full & 0xFFFFFFFE00000000);
    std::cout << "FIRST: " << first << std::endl;
    Result I am getting:

    FIRST: 13527612313275727872

    Which is 0x12C5F92C33333333 .

    I was expecting 0xBBBBBBBA00000000 .


    UPDATE.

    Looks like the problem is with initialising 'full'.

    For this code:
    Code:
    Primitive<uint64_t> full = 0xBBBBBBBBCCCCCCCCULL;
    unsigned long long f = 0xBBBBBBBBCCCCCCCCULL;
    std::cout << "f: " << f << std::endl;
    std::cout << "full: " << full << std::endl;
    I also get the same result:

    f: 13527612321006669004
    full: 13527612321006669004

    UPDATE 2.

    Was a problem with std::cout - was printing numbers as negative for some reason.
    Problem solved now.
    Last edited by mondaytofriday; 06-25-2013 at 02:10 AM. Reason: update

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 03-06-2012, 04:44 PM
  2. Working with clock(); getting unexpected result
    By matrixx333 in forum C Programming
    Replies: 16
    Last Post: 06-03-2010, 11:28 AM
  3. unexpected result
    By abotaha in forum C++ Programming
    Replies: 14
    Last Post: 11-17-2009, 08:32 PM
  4. No error, but the result is unexpected
    By Nimbuz in forum C Programming
    Replies: 10
    Last Post: 07-24-2009, 03:10 PM
  5. an unexpected result.
    By System_159 in forum C Programming
    Replies: 7
    Last Post: 01-22-2008, 07:05 AM

Tags for this Thread