【问题标题】:Parse decimal from textblock (string) and convert to hexidecimal从文本块(字符串)解析十进制并转换为十六进制
【发布时间】:2013-12-20 08:23:45
【问题描述】:

好吧,假设我将其输入到富文本框中:

private void noRecoilOn()
{
    this.Jtag.WriteUInt32(2200480928u, 1024u);
}
private void noRecoilOff()
{
    this.Jtag.WriteUInt32(2200480928u, 0u);
}

我希望能够解析出小数并将其转换为十六进制,如下所示:

private void noRecoilOn()
{
    this.Jtag.WriteUInt32(0x8328ACA0, 0x400);
}
private void noRecoilOff()
{
    this.Jtag.WriteUInt32(0x8328ACA0, 0x0);
}

这只是一个简单的示例,但我将要转换的实际内容将是具有许多不同小数的整个代码块需要转换,而不仅仅是“2200480928u”。

我将如何去做。我不知道

【问题讨论】:

  • 你的意思是显示为十六进制吗?
  • 所以它接受输入,带小数,然后在另一个富文本框中,显示相同的代码,但用十六进制而不是小数

标签: c# parsing hex xbox360


【解决方案1】:

我建议查看How to: Convert Between Hexadecimal Strings and Numeric Types (C# Programming Guide)

另外ToString() 有一个format to write to HexUInt32.Parse 可以是provided an IFormat

uint num = 2200480928u;

// Converts the uint to a hex string
string hex = num.ToString("X");


// Convert the hex string back to the number
uint number = UInt32.Parse(hex, System.Globalization.NumberStyles.HexNumber);

【讨论】:

  • 我回家后试试这个。我唯一的另一个问题是如何从通过输入的代码块中解析出 uint?
  • @user2692560 您需要找到合适的模式来搜索和替换。可能是像 "[0-9]+u" 这样的正则表达式。但这假设所有跟在 u 后面的数字都应该改变。
  • 这种模式很适合我的需要,但是有没有办法编辑它,所以它只会替换一定长度的 uint?例如,仅替换 7 个字符长的 uint
  • "[0-9]{7}u" 将查找 7 个数字,后跟 au 和 "[0-9]{7,}u " 将查找至少 7 个数字,后跟一个 u。 see this
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-01-22
  • 1970-01-01
  • 2018-01-31
  • 2012-02-03
  • 2017-08-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多