Reputation: 561
Why does the compiler fail with this error: 'Cannot implicitly convert uint to int' when I do this?:
int bits = 0b1001_1000_0000_0000_0000_0000_0000_0000;
Upvotes: 2
Views: 167
Reputation: 2385
0b1001_1000_0000_0000_0000_0000_0000_0000
is an uint
value. What you can do is explictly convert it to int
, here with unchecked
to allow for negative numbers (when given value exceeds Int32.MaxValue
):
int bits = unchecked((int)0b1001_1000_0000_0000_0000_0000_0000_0000);
In this example you will have bits == -1744830464
Upvotes: 4