PDA

View Full Version : نیاز به توابع تبدیل



f.sh_a
شنبه 17 تیر 1385, 09:12 صبح
سلام
من به یک تابع نیاز دارم که کار زیر رو برام انجام بده.

یک مقدار مثل C0 رو بگیره
بهش0x0 اضافه کنه یا اونو تبدیل کنه به هگز
سپس مقدار اسکی این هگز رو بده
من خودم سعی کردم بنویسم نشد .

M.GhanaatPisheh
شنبه 17 تیر 1385, 12:06 عصر
این C0 چیه که باید تبدیل به هگز شه؟
کدهای زیر رو ببینید :

// To hold our converted unsigned integer32 value
uint uiDecimal = 0;

try
{
// Convert text string to unsigned integer
uiDecimal = checked((uint)System.Convert.ToUInt32(tbDecimal.Te xt));
}

catch (System.OverflowException exception)
{
// Show overflow message and return
tbHex.Text = "Overflow";
return;
}

// Format unsigned integer value to hex and show in another textbox
tbHex.Text = String.Format("{0:x2}", uiDecimal);

و برعکس :


// To hold our converted unsigned integer32 value
uint uiHex = 0;

try
{
// Convert hex string to unsigned integer
uiHex = System.Convert.ToUInt32(tbHex.Text, 16);
}

catch (System.OverflowException exception)
{
// Show overflow message and return
tbDecimal.Text = "Overflow";
return;
}

// Format it and show as a string
tbDecimal.Text = uiHex.ToString();

ghafoori
شنبه 17 تیر 1385, 15:33 عصر
در ضمن دوست عزیز visual basic.net یک تابع بنام hex دارد که یک عدد میگیرد و معادل hex ان را میدهد فکر کنم بکارت بیاد برای استفاده از این تابع باید microsoft.visualbasic.dll را به برنامت اضافه کنی و با دستور زیر از ان استفاده کنی
microsoft.visualbasic.hex