Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert type 'uint' to 'int' in C#

Tags:

c#

I am trying to assign an int to an hex number. const int a = 0xFFFFFFF0; I got an error: Cannot implicitly convert type 'uint'. An explicit conversion exsist (are you missing a cast?) Does someone know how to fix it? tnx

like image 856
jerry Avatar asked Mar 24 '11 11:03

jerry


2 Answers

    const int a = unchecked((int)0xFFFFFFF0);

or simpler:

    const int a = -16;
like image 130
Marc Gravell Avatar answered Sep 22 '22 14:09

Marc Gravell


use

const uint a = 0xFFFFFFF0

;-)

Background: 0xFFFFFFF0 is too big to fit into an int, which goes from − 2,147,483,648 to 2,147,483,647, where as uint goes from 0 to 4,294,967,295, which is just above 0xFFFFFFF0 (= 4,294,967,280).

like image 38
Daniel Hilgarth Avatar answered Sep 19 '22 14:09

Daniel Hilgarth