开发者

Two's complement on an unsigned integer in VB.NET

How can I implement a two's complement in VB.NET using unsigned integer types such as Byte, UShort, UInteger and UL开发者_如何学Goong? Can I cast a UInteger to an Integer?


No, you can't cast. That will result in an overflow exception for large values.
You can, however, do this:

intValue = BitConverter.ToInt32(BitConverter.GetBytes(uintValue), 0)

But what stops you from doing the math with the unsigned values without casting them to something? It just works.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜