convert the byte to a unsigned char

  • Thread starter Thread starter puzzlecracker
  • Start date Start date
P

puzzlecracker

int i;
char='c';

How can it be done in csharp portably, is it somethig like that: i= c
& 0x00FF;


are there generic functions for this sort of operations?

thx
 
puzzlecracker said:
int i;
char='c';

How can it be done in csharp portably, is it somethig like that: i= c
& 0x00FF;


are there generic functions for this sort of operations?

thx

A char is a 16 bit value, you can just convert it to an int without
loosing any data:

i = (int)c;

If you are talking about an unsigned char as in C, that is the same as a
byte in .NET, so there is no conversion at all.
 
Göran Andersson said:
A char is a 16 bit value, you can just convert it to an int without
loosing any data:

i = (int)c;

The cast is not even needed.

Arne
 
Back
Top