简体   繁体   中英

In C#, how do I extract the two UInt64 values that make up a UInt128?

Suppose I have a UInt128 like this

UInt64 upperA = 7, lowerA = 8;
UInt128 foo = new(upperA, lowerA);
++foo;

And now I want to extract the two UInt64s from the updated foo.
If they were properties, I could do this

UInt64 upperB = foo.Upper, lowerB = foo.Lower;

But they aren't, so how do I get them?

By converting to UInt64 you can get the lower bits already; to get the upper one you can apply a bit shift first:

var lower = (UInt64)foo;
var upper = (UInt64)(foo >> 64);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM