Reputation: 45
I have a following c++ code which needs to convert to c#.
char tempMask;
tempMask = 0xff;
I am not too sure how to convert this, could some one please let me know what is the use of below line in c++
tempMask = 0xff;
thanks
Upvotes: 1
Views: 353
Reputation: 6542
A signed char in C/C++ is not a 'char' in C#, it's an 'sbyte' - no cast required:
sbyte tempMask;
tempMask = 0xff;
Upvotes: 0
Reputation: 2879
It's just a simple initialisation of a variable tempMask in a hexadecimal system. http://en.wikipedia.org/wiki/Hexadecimal
OxFF = 15*16^0+ 15*16^1 = 255 .
In C# you cannot init char with int value without explicit conversion but you can write : char tempMask = (char)0xFF;
, or if you really want a 8-bit integer - try byte tempMask = 0xFF;
Upvotes: 1
Reputation: 30489
It initializes tempMask
with a byte containing value 0xFF
In C#, you can write
tempMask = (char)0xff;
or
tempMask = Convert.ToChar(0xff);
Upvotes: 5