1

JavaのInteger.toHexString()に相当するC#は何ですか?

4

2 に答える 2

2

String.Format("{0:x}", x)静的メソッドまたはメソッドを使用しますInt32.ToString("x")

例を参照してください。

using System;
using System.Globalization;

class Program
{
static void Main()
{
    int x = 4067;
    string s = x.ToString("x");
    Console.WriteLine(s);      // fe3

    s = String.Format("{0:x}", x);
    Console.WriteLine(s);      // fe3

    s = String.Format("{0:X}", x);
    Console.WriteLine(s);      // FE3

    s = String.Format("{0:x6}", x);
    Console.WriteLine(s);      // 000fe3
}
}
于 2012-04-30T02:54:02.687 に答える
0

以下は16進数に変換されます

int myInt = 222;
string hexString = myInt.ToString("x")

MSDN リンク

于 2012-04-30T02:51:01.470 に答える