Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. What is meaning of "unsigned int Date :5;" in structure ?
Forum Updated to NodeBB v4.3 + New Features

What is meaning of "unsigned int Date :5;" in structure ?

Scheduled Pinned Locked Moved Solved C++ Gurus
4 Posts 4 Posters 585 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    Qt embedded developer
    wrote on last edited by
    #1

    I have seen one code where i found structure declared like below. i want to know what is meaning of

    unsigned int Date :5;

    in this structure ?

     struct structDateStamp
        {
        	unsigned int Date 	:5;
        	unsigned int Month  :4;
        	unsigned int Year 	:5;
        	unsigned int Hour 	:5;
        	unsigned int Min 	:6;
        	unsigned int Sec 	:6;
        };
    
    jsulmJ J.HilkJ 2 Replies Last reply
    0
    • Q Qt embedded developer

      I have seen one code where i found structure declared like below. i want to know what is meaning of

      unsigned int Date :5;

      in this structure ?

       struct structDateStamp
          {
          	unsigned int Date 	:5;
          	unsigned int Month  :4;
          	unsigned int Year 	:5;
          	unsigned int Hour 	:5;
          	unsigned int Min 	:6;
          	unsigned int Sec 	:6;
          };
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Qt-embedded-developer This struct is a bit-field, see https://docs.microsoft.com/en-us/cpp/cpp/struct-cpp?view=msvc-170
      Date consumes first 5 bits, Month next 4 and so on.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      4
      • Q Qt embedded developer

        I have seen one code where i found structure declared like below. i want to know what is meaning of

        unsigned int Date :5;

        in this structure ?

         struct structDateStamp
            {
            	unsigned int Date 	:5;
            	unsigned int Month  :4;
            	unsigned int Year 	:5;
            	unsigned int Hour 	:5;
            	unsigned int Min 	:6;
            	unsigned int Sec 	:6;
            };
        
        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #3

        @Qt-embedded-developer I actually had to look that up!
        Those are bit fields. Basically, the number after the colon describes how many bits that field uses.

        Credits link


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        1
        • V Offline
          V Offline
          vamsi_siddhani
          wrote on last edited by vamsi_siddhani
          #4

          bitfields.png

          1 Reply Last reply
          2

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved