how to unsigned int64 to two unsigned int32 values
-
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.
-
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.
-
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).
-
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).
-
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.
-
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.
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
-
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
Yes, this will give you correct results irrespective of the endian-ness.
«_Superman_» _I love work. It gives me something to do between weekends.
-
Yes, this will give you correct results irrespective of the endian-ness.
«_Superman_» _I love work. It gives me something to do between weekends.