user2380317
user2380317

Reputation: 25

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. 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

UPD: It was all sunny and such with Oded answer, but then i tried to use the same trick on sbyte.

Upvotes: 0

Views: 111

Answers (1)

I4V
I4V

Reputation: 35363

Easy,

int u = 0x9ecd;
int i = (short)u;

i will be -24883

Upvotes: 3

Related Questions