利用DotNet库函数将八进制数转化为十六进制数

<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span lang="EN-US" style=""><span style=""><font color="#000000"> </font></span><span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;summary&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;<p></p></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span lang="EN-US" style=""><span style=""><font color="#000000"> </font></span><span style="color: gray;">///</span><span style="color: green;"> </span></span><span style="">将八进制数转换为十六进制数<span lang="EN-US"><p></p></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span lang="EN-US" style=""><span style=""><font color="#000000"> </font></span><span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;/summary&gt;<p></p></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span lang="EN-US" style=""><span style=""><font color="#000000"> </font></span><span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;param name="convertFrom"&gt;</span></span><span style="">八进制数</span><span lang="EN-US" style="">&lt;/param&gt;<p></p></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span lang="EN-US" style=""><span style=""><font color="#000000"> </font></span><span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;returns&gt;</span></span><span style="">十六进制数</span><span lang="EN-US" style="">&lt;/returns&gt;<p></p></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span lang="EN-US" style=""><span style=""><font color="#000000"> </font></span><span style="color: blue;">private</span><font color="#000000"> </font><span style="color: blue;">string</span><font color="#000000"> <span style="color: black;">ConvertNumber8To16</span>(</font><span style="color: blue;">string</span><font color="#000000"> <span style="color: black;">convertFrom</span>)<p></p></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span lang="EN-US" style=""><font color="#000000"><span style=""> </span>{<p></p></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span lang="EN-US" style=""><span style=""><font color="#000000"> </font></span><span style="color: blue;">string</span><font color="#000000"> <span style="color: black;">check</span> = <span style="color: black;">convertFrom</span>.<span style="color: black;">Replace</span>(</font><span style="color: maroon;">"0"</span><font color="#000000">, </font><span style="color: blue;">string</span><font color="#000000">.<span style="color: black;">Empty</span>).<span style="color: black;">Replace</span>(</font><span style="color: maroon;">"1"</span><font color="#000000">, </font><span style="color: blue;">string</span><font color="#000000">.<span style="color: black;">Empty</span>).<span style="color: black;">Replace</span>(</font><span style="color: maroon;">"2"</span><font color="#000000">, </font><span style="color: blue;">string</span><font color="#000000">.<span style="color: black;">Empty</span>).<span style="color: black;">Replace</span>(</font><span style="color: maroon;">"3"</span><font color="#000000">, </font><span style="color: blue;">string</span><font color="#000000">.<span style="color: black;">Empty</span>).<span style="color: black;">Replace</span>(</font><span style="color: maroon;">"4"</span><font color="#000000">, </font><span style="color: blue;">string</span><font color="#000000">.<span style="color: black;">Empty</span>).<span style="color: black;">Replace</span>(</font><span style="color: maroon;">"5"</span><font color="#000000">, </font><span style="color: blue;">string</span><font color="#000000">.<span style="color: black;">Empty</span>).<span style="color: black;">Replace</span>(</font><span style="color: maroon;">"6"</span><font color="#000000">, </font><span style="color: blue;">string</span><font color="#000000">.<span style="color: black;">Empty</span>).<span style="color: black;">Replace</span>(</font><span style="color: maroon;">"7"</span><font color="#000000">, </font><span style="color: blue;">string</span><font color="#000000">.<span style="color: black;">Empty</span>);<p></p></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span lang="EN-US" style=""><span style=""><font color="#000000"> </font></span><span style="color: blue;">if</span><font color="#000000"> (<span style="color: black;">check</span>.<span style="color: black;">Length</span> &gt; 0)<p></p></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span lang="EN-US" style=""><font color="#000000"><span style=""> </span>{<p></p></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span lang="EN-US" style=""><span style=""><font color="#000000"> </font></span><span style="color: green;">//errorHandle<p></p></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span lang="EN-US" style=""><span style=""><font color="#000000"> </font></span><span style="color: blue;">return</span><font color="#000000"> </font><span style="color: blue;">string</span><font color="#000000">.<span style="color: black;">Empty</span>;<p></p></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span lang="EN-US" style=""><font color="#000000"><span style=""> </span>}<p></p></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span lang="EN-US" style=""><span style=""><font color="#000000"> </font></span><span style="color: blue;">string</span><font color="#000000"> <span style="color: black;">convertTo</span>;</font><span style="color: green;">//</span></span><span style="">转化为进制数<span lang="EN-US">convertTo<p></p></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span lang="EN-US" style=""><span style=""><font color="#000000"> </font></span><span style="color: blue;">int</span><font color="#000000"> <span style="color: black;">convertToTemp</span> = </font><span style="color: teal;">Convert</span><font color="#000000">.<span style="color: black;">ToInt32</span>(<span style="color: black;">convertFrom</span>,8);</font><span style="color: green;">//</span></span><span style="">先转换为十进制<span lang="EN-US"><p></p></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span lang="EN-US" style=""><font color="#000000"><span style=""> </span><span style="color: black;">convertTo</span> = <span style="color: black;">convertToTemp</span>.<span style="color: black;">ToString</span>(</font><span style="color: maroon;">"X"</span><font color="#000000">);</font><span style="color: green;">//</span></span><span style="">转换为十六进制<span lang="EN-US"><p></p></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span lang="EN-US" style=""><span style=""><font color="#000000"> </font></span><span style="color: blue;">return</span><font color="#000000"> <span style="color: black;">convertTo</span>;<p></p></font></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US" style=""><font color="#000000"><span style=""> </span>}</font></span></p>

你可能感兴趣的:(十六进制)