[英]Way to get signed value from unsigned and vice versa
So... For example i have some number like 9ecd
which one is 40653
BUT i want to use it like signed -24883
. 所以...例如,我有一些像
9ecd
这样的9ecd
,其中一个是40653
但我想像签名-24883
那样使用它。 So, is there any way to do it without "sing bit"-workaround by ">>15" (sic!) if i even cant use it at declaration at this point 因此,有没有办法在没有“唱位”的情况下做到这一点-如果我现在无法在声明时使用“ >> 15”(原文如此!)
UPD: It was all sunny and such with Oded answer, but then i tried to use the same trick on sbyte. UPD:到处都是晴天,奥德(Oded)的回答如此,但后来我尝试对sbyte使用相同的技巧。
Easy, 简单,
int u = 0x9ecd;
int i = (short)u;
i
will be -24883
i
将是-24883
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.