Convert int to hex

1

What do I want to do, is it possible? convert the value variable to hex.

private void button1_Click(object sender, EventArgs e)
{
        int value = 255;
        byte[] buffer = new byte[5];
        buffer[0] = 0xff;
        buffer[1] = value; //eu preciso converter esse value para hex.
                           //igual ao buffer[0] , tem como?    
}
    
asked by anonymous 31.01.2017 / 16:26

2 answers

1
int intValue = 182;

string hexValue = intValue.ToString("X");

int intAgain = int.Parse(hexValue,System.Globalization.NumberStyles.HexNumber);
    
31.01.2017 / 16:42
1

Value decimal to hexadecimal use ToString (" X ") :

int value = 255;
string hexValue = value.ToString("X");

Output:

FF

Example

References

31.01.2017 / 16:47