将数字转换成.NET中的十六进制值 [英] Convert a number into the hex value in .NET

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

问题描述

我需要一个整数转换为十六进制值。它看起来是这样的:

I need to convert an integer number to the hex value. It will look like this:

0x0201cb77192c851c

当我这样做。

string hex = int.ToString("x")

在C#中,它返回

201cb77192c851c

我怎样才能得到所需的结果?

How can I get the required result?

推荐答案

的一种方法是要追加的需要的位数,×之后。这将用前导零在必要时输出。

One way would be to append the number of digits you need, after "x". This will pad the output with leading zeros as necessary.

"0x" + myLong.ToString("x16");

string.Format("0x{0:x16}", myLong);



从的The十六进制(X)格式说明

精度说明表示在
生成的字符串所需位数
最小数量。如果需要,将
号码用零填充到
左边以产生由精度说明给定数字
的数目

The precision specifier indicates the minimum number of digits desired in the resulting string. If required, the number is padded with zeros to its left to produce the number of digits given by the precision specifier.

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

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