Thread: Why this bitwise do not work?

  1. #1
    Registered User
    Join Date
    Feb 2019
    Posts
    40

    Why this bitwise do not work?

    Hi everyone,

    I believe that this is very simple but I cannot figure out why the following bitwise operation do not work

    Code:
     // Get the unique identifier of the device
      uint32_t msb;
      uint32_t lsb;
    
    
      lsb = NRF_FICR->DEVICEID[0]; // read the less significant 32bits
      msb = NRF_FICR->DEVICEID[1]; // read the most significant 32bits
      uint64_t deviceID = (uint64_t)msb << 32 || lsb; // 64 bit unique device identifier
    
    
      NRF_LOG_INFO("lsb: %x", lsb);
      NRF_LOG_INFO("msb: %x", msb);
      NRF_LOG_INFO("Device ID: %x", deviceID);
    As you can see I can read normally lsb and msb but the deviceID is 1

    Why this bitwise do not work?-screenshot_82-png

    Any advice?

    Nick

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,995
    You used || instead of |

    I'm a bit puzzled why you would use bitwise or though: wouldn't that mean that differing msb and lsb parts can result in the same device id?

    EDIT: oh, I misread the shift direction, so that's okay as you're combining rather than losing information
    Last edited by laserlight; 3 Weeks Ago at 03:11 PM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Feb 2019
    Posts
    40
    I told you that this is a simple one!! Thanks, I didn't notice!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bitwise
    By Charles Ontiti in forum C Programming
    Replies: 1
    Last Post: 02-20-2015, 08:09 AM
  2. Bitwise -- b&01
    By ilans11il in forum C Programming
    Replies: 4
    Last Post: 04-22-2013, 03:16 PM
  3. Bitwise...
    By tennisstar in forum C++ Programming
    Replies: 4
    Last Post: 12-05-2012, 05:34 AM
  4. bitwise? am i right?
    By skiz in forum C Programming
    Replies: 10
    Last Post: 03-11-2009, 11:37 PM
  5. Bitwise OR
    By tinkerbell20 in forum C++ Programming
    Replies: 4
    Last Post: 06-11-2005, 02:23 AM

Tags for this Thread