将数字转换为十六进制并发症 [英] Converting Number to Hex with complications

查看:95
本文介绍了将数字转换为十六进制并发症的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



这与星期五一些字符串生成器问题的问题有关,现在对转换包含的字符串感到有点悲伤整数到十六进制值。我正在尝试一点点播放后得到一个值,这是一个转换为字符串的整数我试图做以下工作过去

  //  将Int解析为十六进制 

Value_Hex =(Value.ToString(< span class =code-string> x)); // < span class =code-comment> String.Format(Value {0:x2,numericUpDown1.Value}
MessageBox.Show(Value_Hex.ToString());

但是我今天似乎无法正常工作这是正确的方法吗?

我用来将基数10转换为十六进制的方法是

 Value_Int =  int  .Parse(ValueUPDwn.ToString(),System.Globalization.NumberStyles.HexNumber); 

但是我无法通过intellisense看到它会有用。

Glenn

解决案

要转换,我使用以下方法:

十六进制字符串到int:

  int  i = Convert.ToInt32(  18da06f1 16 ); 



Int到十六进制字符串:

  string  s = i.ToString(  X); 

这些对我来说每次都有效...


嗨格伦,



查看以下示例:



  public   class 示例
{
public static void Main()
{
short [] values = { Int16的 .MinVa lue,-27, 0 1042 Int16 .MaxValue};
Console.WriteLine( {0,10} {1,10} \ n 十进制 < span class =code-string> Hex);
foreach 简短 价值 in values)
{
string formatString = 字符串 .Format( {0,10:G}:{0,10:X } value );
Console.WriteLine(formatString);
}
}
}
// 该示例显示以下内容输出:
// 十进制十六进制
//
// -32768:8000
// -27:FFE5
// 0:0
// 1042:412
// 32767:7FFF





干杯,

Edo


您好,



有不同的解决方案:



  int  decValue =  182  ; 
// 将整数182转换为字符串变量中的十六进制
string hexValue = decValue.ToString( X );
// 将十六进制字符串转换回数字
int decAgain = int .Parse(hexValue,System.Globalization.NumberStyles.HexNumber);

< br $> b $ b





 string hexOutput = String.Format({0:X },value); 





谢谢


Hi All,

This is related to a question on Friday "Some String Builder Problems" which is sorted now a bit of grief with converting the string which contains integers to Hex values. I am trying after a little playing to get a value which is an integer converted to a string I am trying to do the following which has worked in the past

//parse an Int to a Hex

          Value_Hex =(Value.ToString("x"));// String.Format(Value{"0:x2",numericUpDown1.Value}
          MessageBox.Show(Value_Hex.ToString());

but I can''t seem to get it working today that is the right way of doing it?
A method I have used to convert from base 10 to Hex is

Value_Int = int.Parse(ValueUPDwn.ToString(), System.Globalization.NumberStyles.HexNumber);

but I can''t see via the intellisense that would be of use.
Glenn

解决方案

To convert, I use these methods:
Hex string to int:

int i = Convert.ToInt32("18da06f1",16);


Int to hex string:

string s = i.ToString("X");

These work every time for me...


Hi Glenn,

Check out the following example:

public class Example
{
   public static void Main()
   {
      short[] values= { Int16.MinValue, -27, 0, 1042, Int16.MaxValue };
      Console.WriteLine("{0,10}  {1,10}\n", "Decimal", "Hex");
      foreach (short value in values)
      {
         string formatString = String.Format("{0,10:G}: {0,10:X}", value);
         Console.WriteLine(formatString);
      }   
   }
}
// The example displays the following output: 
//       Decimal         Hex 
//     
//        -32768:       8000 
//           -27:       FFE5 
//             0:          0 
//          1042:        412 
//         32767:       7FFF



Cheers,
Edo


Hi,

There are different solutions:

int decValue = 182;
// Convert integer 182 as a hex in a string variable
string hexValue = decValue.ToString("X");
// Convert the hex string back to the number
int decAgain = int.Parse(hexValue, System.Globalization.NumberStyles.HexNumber);



or

string hexOutput = String.Format("{0:X}", value);



Thanks


这篇关于将数字转换为十六进制并发症的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆