Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. how to unsigned int64 to two unsigned int32 values

how to unsigned int64 to two unsigned int32 values

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
9 Posts 3 Posters 0 Views 1 Watching
  • 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.
  • V Offline
    V Offline
    vishalgpt
    wrote on last edited by
    #1

    How to convert _uint64 into two _uint32 values and vice versa.

    Regards, Vishal

    J _ 2 Replies Last reply
    0
    • V vishalgpt

      How to convert _uint64 into two _uint32 values and vice versa.

      Regards, Vishal

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      By shifting the high part and casting:

      _uint64 ui64 = 1234;
      _uint32 lo = (_uint32)ui64;
      _uint32 hi = (_uint32)(ui64 >> 32);

      ui64 = (_uint64)lo | ((_uint64)hi) << 32;

      [EDIT:] Added code formatting.

      V 1 Reply Last reply
      0
      • J Jochen Arndt

        By shifting the high part and casting:

        _uint64 ui64 = 1234;
        _uint32 lo = (_uint32)ui64;
        _uint32 hi = (_uint32)(ui64 >> 32);

        ui64 = (_uint64)lo | ((_uint64)hi) << 32;

        [EDIT:] Added code formatting.

        V Offline
        V Offline
        vishalgpt
        wrote on last edited by
        #3

        does it take endianness into consideration, (Little/Big Endian)

        Regards, Vishal

        J 1 Reply Last reply
        0
        • V vishalgpt

          does it take endianness into consideration, (Little/Big Endian)

          Regards, Vishal

          J Offline
          J Offline
          Jochen Arndt
          wrote on last edited by
          #4

          Yes, because the endianess does not care for the used logical operations. If you think of multiplication / division instead of the shift operations and of addition instead of the OR operation it should be clear. The operation values are just high or low parts where the internally used bit or byte order does not care. Casting is similar (extending with high zeroes upon up-casting and masking out the lower bits upon down-casting).

          V 1 Reply Last reply
          0
          • J Jochen Arndt

            Yes, because the endianess does not care for the used logical operations. If you think of multiplication / division instead of the shift operations and of addition instead of the OR operation it should be clear. The operation values are just high or low parts where the internally used bit or byte order does not care. Casting is similar (extending with high zeroes upon up-casting and masking out the lower bits upon down-casting).

            V Offline
            V Offline
            vishalgpt
            wrote on last edited by
            #5

            Thank you.. :)

            Regards, Vishal

            1 Reply Last reply
            0
            • V vishalgpt

              How to convert _uint64 into two _uint32 values and vice versa.

              Regards, Vishal

              _ Offline
              _ Offline
              _Superman_
              wrote on last edited by
              #6

              Here is another way to do it using the LARGE_INTEGER[^] union.

              LARGE_INTEGER lint;
              lint.QuadPart = 12345; // Assigning 64-bit value;
              // lint.LowPart and lint.HighPart can now be used to split the value;

              «_Superman_»  _I love work. It gives me something to do between weekends.

              _Microsoft MVP (Visual C++) (October 2009 - September 2013)

              Polymorphism in C

              V 1 Reply Last reply
              0
              • _ _Superman_

                Here is another way to do it using the LARGE_INTEGER[^] union.

                LARGE_INTEGER lint;
                lint.QuadPart = 12345; // Assigning 64-bit value;
                // lint.LowPart and lint.HighPart can now be used to split the value;

                «_Superman_»  _I love work. It gives me something to do between weekends.

                _Microsoft MVP (Visual C++) (October 2009 - September 2013)

                Polymorphism in C

                V Offline
                V Offline
                vishalgpt
                wrote on last edited by
                #7

                I too came across the union while using GetFileSize function. does it produces same result in little endian and big endian systems. as i want this for encryption section, where i had to convert 64bit unsigned integer to two 32 bit unsigned integer and vice versa, So looking for results on little endian and big endian system result.

                Regards, Vishal

                _ 1 Reply Last reply
                0
                • V vishalgpt

                  I too came across the union while using GetFileSize function. does it produces same result in little endian and big endian systems. as i want this for encryption section, where i had to convert 64bit unsigned integer to two 32 bit unsigned integer and vice versa, So looking for results on little endian and big endian system result.

                  Regards, Vishal

                  _ Offline
                  _ Offline
                  _Superman_
                  wrote on last edited by
                  #8

                  Yes, this will give you correct results irrespective of the endian-ness.

                  «_Superman_»  _I love work. It gives me something to do between weekends.

                  _Microsoft MVP (Visual C++) (October 2009 - September 2013)

                  Polymorphism in C

                  V 1 Reply Last reply
                  0
                  • _ _Superman_

                    Yes, this will give you correct results irrespective of the endian-ness.

                    «_Superman_»  _I love work. It gives me something to do between weekends.

                    _Microsoft MVP (Visual C++) (October 2009 - September 2013)

                    Polymorphism in C

                    V Offline
                    V Offline
                    vishalgpt
                    wrote on last edited by
                    #9

                    very very thank you sir.

                    Regards, Vishal

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups