Convert int to hex
What I want to do is 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?
}
1
2 answers
int intValue = 182;
string hexValue = intValue.ToString("X");
int intAgain = int.Parse(hexValue,System.Globalization.NumberStyles.HexNumber);
1
Author: Eduardo Sampaio, 2017-01-31 15:42:47
Value decimal
for hexadecimal
Use ToString ("X"):
int value = 255;
string hexValue = value.ToString("X");
output:
FF
References:
0
Author: novic, 2017-01-31 15:52:43