- Jul 22, 2012
- 3,217
- 2
- 81
This seems like the most basic thing in the world. How do I make C# see hex numbers?
All I'm trying to do is convert 0xFFFFFF (black) to an integer. For the time being, signed or unsigned doesn't matter.
Compile error: the expression being assigned to black must be constant.
Compile error: cannot implicitly convert type 'string'.
Compile error: name 'FFFFFF' does not exist in the current context. Cannot implicitly convert type 'string'.
The only thing I can find on the internet that resembles this problem is here:
http://msdn.microsoft.com/en-us/library/swz6z5ks(v=vs.110).aspx
Convert.ToUInt32("0FFFFFFF", 16);
Which returns an error: the expression assigned to black must be constant.
All I'm trying to do is convert 0xFFFFFF (black) to an integer. For the time being, signed or unsigned doesn't matter.
Code:
black = Convert.ToInt32(0xFFFFFF);
Code:
black = Convert.ToInt32('0xFFFFFF');
Code:
black = Convert.ToInt32(FFFFFF, 16);
The only thing I can find on the internet that resembles this problem is here:
http://msdn.microsoft.com/en-us/library/swz6z5ks(v=vs.110).aspx
Which is pretty much what I'm doing. The second iteration of that loop would be:Code:string[] hexStrings = { "80000000", "0FFFFFFF", "F0000000", "00A3000", "D", "-13", "9AC61", "GAD", "FFFFFFFFFF" }; foreach (string hexString in hexStrings) { Console.Write("{0,-12} --> ", hexString); try { uint number = Convert.ToUInt32(hexString, 16); ......
Convert.ToUInt32("0FFFFFFF", 16);
Which returns an error: the expression assigned to black must be constant.