积极答复者
十进制转换为指定格式的十六进制

问题
-
我这有一个十进制的字符串,长度为10位,如下:
2359344395 或者 0000234345, 长度限制10个字节,不够的左端自动补0.
项目需要,需要把其转换为指定格式的十六进制字符串;格式如下:
[%02x%02x%02x%02x%02x]
%02x: 表示在输出一个小于2位的十六进制字符串时, 将在前面补0使其总宽度为2位。
我应该怎么转换呢?
MVC 深入研究 博客:http://www.cnblogs.com/DoduNet/
MvcMovieStore 示例网站:MVC 影视 http://MvcMovie.cn/- 已编辑 Dodu.NET 2014年7月11日 7:55
答案
-
经过研究,我自己解决了.
MVC 深入研究 博客:http://www.cnblogs.com/DoduNet/
MvcMovieStore 示例网站:MVC 影视 http://MvcMovie.cn/- 已标记为答案 Dodu.NET 2014年7月12日 10:00
-
现在给出解决办法,对应我给的一个结果:
Private Function GetCardX(cardnum As String) As String Dim result As String = String.Empty, tmpstr As String = Integer.Parse(cardnum).ToString("X") If (tmpstr.Length < cardnum.Length) Then tmpstr = tmpstr.PadLeft(cardnum.Length, "0") For i = tmpstr.Length - 2 To 0 Step -2 result &= tmpstr.Substring(i, 2) Next Return result End Function
MVC 深入研究 博客:http://www.cnblogs.com/DoduNet/
MvcMovieStore 示例网站:MVC 影视 http://MvcMovie.cn/- 已标记为答案 Dodu.NET 2014年7月14日 7:04
全部回复
-
补充说明:
这给的有一个转换结果:
十进制:0008765254
转换指定格式的十六进制后的结果:46bf850000
求过程~~~~
MVC 深入研究 博客:http://www.cnblogs.com/DoduNet/
MvcMovieStore 示例网站:MVC 影视 http://MvcMovie.cn/ -
经过研究,我自己解决了.
MVC 深入研究 博客:http://www.cnblogs.com/DoduNet/
MvcMovieStore 示例网站:MVC 影视 http://MvcMovie.cn/- 已标记为答案 Dodu.NET 2014年7月12日 10:00
-
你好:
最好把解决方法也贴出来,这样有类似问题的人看到此贴也会获取到帮助,感谢!
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey. -
现在给出解决办法,对应我给的一个结果:
Private Function GetCardX(cardnum As String) As String Dim result As String = String.Empty, tmpstr As String = Integer.Parse(cardnum).ToString("X") If (tmpstr.Length < cardnum.Length) Then tmpstr = tmpstr.PadLeft(cardnum.Length, "0") For i = tmpstr.Length - 2 To 0 Step -2 result &= tmpstr.Substring(i, 2) Next Return result End Function
MVC 深入研究 博客:http://www.cnblogs.com/DoduNet/
MvcMovieStore 示例网站:MVC 影视 http://MvcMovie.cn/- 已标记为答案 Dodu.NET 2014年7月14日 7:04