Thread: What is the purpose of this bitwise operation?

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

    What is the purpose of this bitwise operation?

    Could someone explain to me the purpose of this bitwise operation?

    Code:
    #define NVMC_CONFIG_WEN_Pos (0UL) /*!< Position of WEN field. */
    #define NVMC_CONFIG_WEN_Msk (0x3UL << NVMC_CONFIG_WEN_Pos) /*!< Bit mask of WEN field. */

    I mean, this is like moving to the left by zero positions the 0x3UL. I do not get it..

  2. #2
    Registered User
    Join Date
    Dec 2017
    Posts
    1,376
    The purpose is to be able to change it to something that is not 0.
    If it is zero then the actual operation will not appear in optimized code.
    A long time ago being crazy meant something. - Charles Manson

  3. #3
    Registered User
    Join Date
    Feb 2019
    Posts
    93
    Hi John and thank you for your reply, still I do not understand it. Could you provide a real case example?

  4. #4
    Registered User
    Join Date
    Dec 2017
    Posts
    1,376
    Do you know what a mask is?
    In this case the mask is two bits in size and positioned with the rightmost bit of the mask at position 0 of the register.
    But what if the rightmost bit of the mask needed to be at position 4?
    In that case you just need to change NVMC_CONFIG_WEN_Pos to 4.
    And if the mask needed to be 3 bits wide instead of 2, you could change NVMC_CONFIG_WEN_Msk to (0x7UL << NVMC_CONFIG_WEN_Pos).
    That's one of the purposes of a define, to parameterize compile-time constants.
    Last edited by john.c; 04-10-2022 at 02:03 PM.
    A long time ago being crazy meant something. - Charles Manson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking bits in a bitwise operation
    By William Putnam in forum C++ Programming
    Replies: 2
    Last Post: 09-22-2013, 11:26 AM
  2. C Bitwise Operation..
    By ahmedBanihammad in forum C Programming
    Replies: 4
    Last Post: 10-31-2010, 09:11 AM
  3. Bitwise operation; flag look up
    By emptythought in forum C Programming
    Replies: 22
    Last Post: 09-08-2010, 06:48 AM
  4. Bitwise operation problem
    By cunnus88 in forum C++ Programming
    Replies: 9
    Last Post: 10-25-2008, 01:49 PM
  5. Bitwise operation
    By Justice in forum C Programming
    Replies: 4
    Last Post: 02-09-2008, 09:06 PM

Tags for this Thread