`
insertyou
  • 浏览: 905139 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

C#利用字符串方法把八进制数转换为十六进制数

 
阅读更多
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;summary&gt;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="font-size: small;"><span style="" lang="EN-US"><span style=""><span style="color: #000000;"> </span></span><span style="color: gray;">///</span><span style="color: green;"> </span></span><span style="">将8进制数转换成16进制数<span lang="EN-US"></span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;/summary&gt;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="font-size: small;"><span style="" lang="EN-US"><span style=""><span style="color: #000000;"> </span></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 style="" lang="EN-US">&lt;/param&gt;</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="font-size: small;"><span style="" lang="EN-US"><span style=""><span style="color: #000000;"> </span></span><span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;returns&gt;</span></span><span style="">十六进制数</span><span style="" lang="EN-US">&lt;/returns&gt;</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">private</span><span style="color: #000000;"> </span><span style="color: blue;">string</span><span style="color: #000000;"> <span style="color: black;">ConvertNumber8To16</span>(</span><span style="color: blue;">string</span><span style="color: #000000;"> <span style="color: black;">convertFrom</span>)</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span>{</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">string</span><span style="color: #000000;"> <span style="color: black;">check</span> = <span style="color: black;">convertFrom</span>.<span style="color: black;">Replace</span>(</span><span style="color: maroon;">"0"</span><span style="color: #000000;">, </span><span style="color: blue;">string</span><span style="color: #000000;">.<span style="color: black;">Empty</span>).<span style="color: black;">Replace</span>(</span><span style="color: maroon;">"1"</span><span style="color: #000000;">, </span><span style="color: blue;">string</span><span style="color: #000000;">.<span style="color: black;">Empty</span>).<span style="color: black;">Replace</span>(</span><span style="color: maroon;">"2"</span><span style="color: #000000;">, </span><span style="color: blue;">string</span><span style="color: #000000;">.<span style="color: black;">Empty</span>).<span style="color: black;">Replace</span>(</span><span style="color: maroon;">"3"</span><span style="color: #000000;">, </span><span style="color: blue;">string</span><span style="color: #000000;">.<span style="color: black;">Empty</span>).<span style="color: black;">Replace</span>(</span><span style="color: maroon;">"4"</span><span style="color: #000000;">, </span><span style="color: blue;">string</span><span style="color: #000000;">.<span style="color: black;">Empty</span>).<span style="color: black;">Replace</span>(</span><span style="color: maroon;">"5"</span><span style="color: #000000;">, </span><span style="color: blue;">string</span><span style="color: #000000;">.<span style="color: black;">Empty</span>).<span style="color: black;">Replace</span>(</span><span style="color: maroon;">"6"</span><span style="color: #000000;">, </span><span style="color: blue;">string</span><span style="color: #000000;">.<span style="color: black;">Empty</span>).<span style="color: black;">Replace</span>(</span><span style="color: maroon;">"7"</span><span style="color: #000000;">, </span><span style="color: blue;">string</span><span style="color: #000000;">.<span style="color: black;">Empty</span>);</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">if</span><span style="color: #000000;"> (<span style="color: black;">check</span>.<span style="color: black;">Length</span> &gt; 0)</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span>{</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: green;">//errorHandle</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">return</span><span style="color: #000000;"> </span><span style="color: blue;">string</span><span style="color: #000000;">.<span style="color: black;">Empty</span>;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span>}</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="font-size: small;"><span style="" lang="EN-US"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">string</span><span style="color: #000000;"> <span style="color: black;">convertTo</span>=</span><span style="color: blue;">string</span><span style="color: #000000;">.<span style="color: black;">Empty</span>, <span style="color: black;">convertTo2</span>;</span><span style="color: green;">//</span></span><span style="">目标数<span lang="EN-US">convertTo</span>:将八进制<span lang="EN-US">From</span>转换成进制<span lang="EN-US">To,</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="font-size: small;"><span style="" lang="EN-US"><span style=""><span style="color: #000000;"> </span></span><span style="color: green;">//convertTo2</span></span><span style="">:选转换成进制数,再转换成十六进制数<span lang="EN-US"></span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="font-size: small;"><span style="" lang="EN-US"><span style="color: #000000;"><span style=""> </span><span style="color: black;">convertTo2</span> = <span style="color: black;">ConvertNumber8To2</span>(<span style="color: black;">convertFrom</span>);</span><span style="color: green;">//</span></span><span style="">先转化为二进制<span lang="EN-US"></span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span><span style="color: black;">convertTo</span> = <span style="color: black;">ConvertNumber2To16</span>(<span style="color: black;">convertTo2</span>);</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">return</span><span style="color: #000000;"> <span style="color: black;">convertTo</span>;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span>}</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;summary&gt;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="font-size: small;"><span style="" lang="EN-US"><span style=""><span style="color: #000000;"> </span></span><span style="color: gray;">///</span><span style="color: green;"> </span></span><span style="">将8进制转换为2进制<span lang="EN-US"></span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;/summary&gt;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="font-size: small;"><span style="" lang="EN-US"><span style=""><span style="color: #000000;"> </span></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 style="" lang="EN-US">&lt;/param&gt;</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="font-size: small;"><span style="" lang="EN-US"><span style=""><span style="color: #000000;"> </span></span><span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;returns&gt;</span></span><span style="">二进制数</span><span style="" lang="EN-US">&lt;/returns&gt;</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">private</span><span style="color: #000000;"> </span><span style="color: blue;">string</span><span style="color: #000000;"> <span style="color: black;">ConvertNumber8To2</span>(</span><span style="color: blue;">string</span><span style="color: #000000;"> <span style="color: black;">convertFrom</span>)</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span>{</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">string</span><span style="color: #000000;"> <span style="color: black;">check</span> = <span style="color: black;">convertFrom</span>.<span style="color: black;">Replace</span>(</span><span style="color: maroon;">"0"</span><span style="color: #000000;">, </span><span style="color: blue;">string</span><span style="color: #000000;">.<span style="color: black;">Empty</span>).<span style="color: black;">Replace</span>(</span><span style="color: maroon;">"1"</span><span style="color: #000000;">, </span><span style="color: blue;">string</span><span style="color: #000000;">.<span style="color: black;">Empty</span>).<span style="color: black;">Replace</span>(</span><span style="color: maroon;">"2"</span><span style="color: #000000;">, </span><span style="color: blue;">string</span><span style="color: #000000;">.<span style="color: black;">Empty</span>).<span style="color: black;">Replace</span>(</span><span style="color: maroon;">"3"</span><span style="color: #000000;">, </span><span style="color: blue;">string</span><span style="color: #000000;">.<span style="color: black;">Empty</span>).<span style="color: black;">Replace</span>(</span><span style="color: maroon;">"4"</span><span style="color: #000000;">, </span><span style="color: blue;">string</span><span style="color: #000000;">.<span style="color: black;">Empty</span>).<span style="color: black;">Replace</span>(</span><span style="color: maroon;">"5"</span><span style="color: #000000;">, </span><span style="color: blue;">string</span><span style="color: #000000;">.<span style="color: black;">Empty</span>).<span style="color: black;">Replace</span>(</span><span style="color: maroon;">"6"</span><span style="color: #000000;">, </span><span style="color: blue;">string</span><span style="color: #000000;">.<span style="color: black;">Empty</span>).<span style="color: black;">Replace</span>(</span><span style="color: maroon;">"7"</span><span style="color: #000000;">, </span><span style="color: blue;">string</span><span style="color: #000000;">.<span style="color: black;">Empty</span>);</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">if</span><span style="color: #000000;"> (<span style="color: black;">check</span>.<span style="color: black;">Length</span> &gt; 0)</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span>{</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: green;">//errorHandle</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">return</span><span style="color: #000000;"> </span><span style="color: blue;">string</span><span style="color: #000000;">.<span style="color: black;">Empty</span>;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span>}</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">string</span><span style="color: #000000;"> <span style="color: black;">convertTo</span> = </span><span style="color: blue;">string</span><span style="color: #000000;">.<span style="color: black;">Empty</span>, <span style="color: black;">bit</span>;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">for</span><span style="color: #000000;"> (</span><span style="color: blue;">int</span><span style="color: #000000;"> <span style="color: black;">i</span> = <span style="color: black;">convertFrom</span>.<span style="color: black;">Length</span> - 1; <span style="color: black;">i</span> &gt;= 0; <span style="color: black;">i</span>--)</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span>{</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span><span style="color: black;">bit</span> = <span style="color: black;">convertFrom</span>.<span style="color: black;">Substring</span>(<span style="color: black;">i</span>, 1);</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">switch</span><span style="color: #000000;"> (<span style="color: black;">bit</span>)</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span>{</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">case</span><span style="color: #000000;"> </span><span style="color: maroon;">"0"</span><span style="color: #000000;">:</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span><span style="color: black;">convertTo</span> = </span><span style="color: maroon;">"000"</span><span style="color: #000000;"> + <span style="color: black;">convertTo</span>;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">break</span><span style="color: #000000;">;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">case</span><span style="color: #000000;"> </span><span style="color: maroon;">"1"</span><span style="color: #000000;">:</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span><span style="color: black;">convertTo</span> = </span><span style="color: maroon;">"001"</span><span style="color: #000000;"> + <span style="color: black;">convertTo</span>;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">break</span><span style="color: #000000;">;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">case</span><span style="color: #000000;"> </span><span style="color: maroon;">"2"</span><span style="color: #000000;">:</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span><span style="color: black;">convertTo</span> = </span><span style="color: maroon;">"010"</span><span style="color: #000000;"> + <span style="color: black;">convertTo</span>;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span><span style=""></span></span><span style="color: blue;">break</span><span style="color: #000000;">;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">case</span><span style="color: #000000;"> </span><span style="color: maroon;">"3"</span><span style="color: #000000;">:</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span><span style="color: black;">convertTo</span> = </span><span style="color: maroon;">"011"</span><span style="color: #000000;"> + <span style="color: black;">convertTo</span>;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">break</span><span style="color: #000000;">;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">case</span><span style="color: #000000;"> </span><span style="color: maroon;">"4"</span><span style="color: #000000;">:</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span><span style="color: black;">convertTo</span> = </span><span style="color: maroon;">"100"</span><span style="color: #000000;"> + <span style="color: black;">convertTo</span>;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">break</span><span style="color: #000000;">;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span><span style=""></span></span><span style="color: blue;">case</span><span style="color: #000000;"> </span><span style="color: maroon;">"5"</span><span style="color: #000000;">:</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span><span style="color: black;">convertTo</span> = </span><span style="color: maroon;">"101"</span><span style="color: #000000;"> + <span style="color: black;">convertTo</span>;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">break</span><span style="color: #000000;">;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">case</span><span style="color: #000000;"> </span><span style="color: maroon;">"6"</span><span style="color: #000000;">:</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span><span style="color: black;">convertTo</span> = </span><span style="color: maroon;">"110"</span><span style="color: #000000;"> + <span style="color: black;">convertTo</span>;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">break</span><span style="color: #000000;">;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">case</span><span style="color: #000000;"> </span><span style="color: maroon;">"7"</span><span style="color: #000000;">:</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span><span style="color: black;">convertTo</span> = </span><span style="color: maroon;">"111"</span><span style="color: #000000;"> + <span style="color: black;">convertTo</span>;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">break</span><span style="color: #000000;">;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span>}</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span>}</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">return</span><span style="color: #000000;"> <span style="color: black;">convertTo</span>;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span>}</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;summary&gt;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="font-size: small;"><span style="" lang="EN-US"><span style=""><span style="color: #000000;"> </span></span><span style="color: gray;">///</span><span style="color: green;"> </span></span><span style="">将2进制转换为16进制<span lang="EN-US"></span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;/summary&gt;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="font-size: small;"><span style="" lang="EN-US"><span style=""><span style="color: #000000;"> </span></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 style="" lang="EN-US">&lt;/param&gt;</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="font-size: small;"><span style="" lang="EN-US"><span style=""><span style="color: #000000;"> </span></span><span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;returns&gt;</span></span><span style="">十六进制数</span><span style="" lang="EN-US">&lt;/returns&gt;</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">private</span><span style="color: #000000;"> </span><span style="color: blue;">string</span><span style="color: #000000;"> <span style="color: black;">ConvertNumber2To16</span>(</span><span style="color: blue;">string</span><span style="color: #000000;"> <span style="color: black;">convertFrom</span>)</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span>{</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">string</span><span style="color: #000000;"> <span style="color: black;">check</span> = <span style="color: black;">convertFrom</span>.<span style="color: black;">Replace</span>(</span><span style="color: maroon;">"0"</span><span style="color: #000000;">, </span><span style="color: blue;">string</span><span style="color: #000000;">.<span style="color: black;">Empty</span>).<span style="color: black;">Replace</span>(</span><span style="color: maroon;">"1"</span><span style="color: #000000;">, </span><span style="color: blue;">string</span><span style="color: #000000;">.<span style="color: black;">Empty</span>);</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">if</span><span style="color: #000000;"> (<span style="color: black;">check</span>.<span style="color: black;">Length</span> &gt; 0)</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span>{</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: green;">//errorHandle</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">return</span><span style="color: #000000;"> </span><span style="color: blue;">string</span><span style="color: #000000;">.<span style="color: black;">Empty</span>;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span>}</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">string</span><span style="color: #000000;"> <span style="color: black;">convertTo</span> = </span><span style="color: blue;">string</span><span style="color: #000000;">.<span style="color: black;">Empty</span>, <span style="color: black;">bit</span>;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">int</span><span style="color: #000000;"> <span style="color: black;">residue</span>,<span style="color: black;">temp</span> = 0;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">for</span><span style="color: #000000;"> (</span><span style="color: blue;">int</span><span style="color: #000000;"> <span style="color: black;">i</span> = <span style="color: black;">convertFrom</span>.<span style="color: black;">Length</span> - 4; <span style="color: black;">i</span> &gt;= 0; <span style="color: black;">i</span>-=4)</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span>{</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="font-size: small;"><span style="" lang="EN-US"><span style="color: #000000;"><span style=""> </span><span style="color: black;">bit</span> = <span style="color: black;">convertFrom</span>.<span style="color: black;">Substring</span>(<span style="color: black;">i</span>, 4);</span><span style="color: green;">//</span></span><span style="">每次减四<span lang="EN-US"></span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">switch</span><span style="color: #000000;"> (<span style="color: black;">bit</span>)</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span>{</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">case</span><span style="color: #000000;"> </span><span style="color: maroon;">"0000"</span><span style="color: #000000;">:</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span><span style="color: black;">convertTo</span> = </span><span style="color: maroon;">"0"</span><span style="color: #000000;"> + <span style="color: black;">convertTo</span>;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">break</span><span style="color: #000000;">;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">case</span><span style="color: #000000;"> </span><span style="color: maroon;">"0001"</span><span style="color: #000000;">:</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span><span style="color: black;">convertTo</span> = </span><span style="color: maroon;">"1"</span><span style="color: #000000;"> + <span style="color: black;">convertTo</span>;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">break</span><span style="color: #000000;">;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">case</span><span style="color: #000000;"> </span><span style="color: maroon;">"0010"</span><span style="color: #000000;">:</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span><span style="color: black;">convertTo</span> = </span><span style="color: maroon;">"2"</span><span style="color: #000000;"> + <span style="color: black;">convertTo</span>;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">break</span><span style="color: #000000;">;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">case</span><span style="color: #000000;"> </span><span style="color: maroon;">"0011"</span><span style="color: #000000;">:</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span><span style="color: black;">convertTo</span> = </span><span style="color: maroon;">"3"</span><span style="color: #000000;"> + <span style="color: black;">convertTo</span>;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">break</span><span style="color: #000000;">;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">case</span><span style="color: #000000;"> </span><span style="color: maroon;">"0100"</span><span style="color: #000000;">:</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span><span style="color: black;">convertTo</span> = </span><span style="color: maroon;">"4"</span><span style="color: #000000;"> + <span style="color: black;">convertTo</span>;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">break</span><span style="color: #000000;">;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">case</span><span style="color: #000000;"> </span><span style="color: maroon;">"0101"</span><span style="color: #000000;">:</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span><span style=""></span><span style="color: black;">convertTo</span> = </span><span style="color: maroon;">"5"</span><span style="color: #000000;"> + <span style="color: black;">convertTo</span>;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">break</span><span style="color: #000000;">;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">case</span><span style="color: #000000;"> </span><span style="color: maroon;">"0110"</span><span style="color: #000000;">:</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span><span style="color: black;">convertTo</span> = </span><span style="color: maroon;">"6"</span><span style="color: #000000;"> + <span style="color: black;">convertTo</span>;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">break</span><span style="color: #000000;">;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">case</span><span style="color: #000000;"> </span><span style="color: maroon;">"0111"</span><span style="color: #000000;">:</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span><span style="color: black;">convertTo</span> = </span><span style="color: maroon;">"7"</span><span style="color: #000000;"> + <span style="color: black;">convertTo</span>;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">break</span><span style="color: #000000;">;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">case</span><span style="color: #000000;"> </span><span style="color: maroon;">"1000"</span><span style="color: #000000;">:</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span><span style="color: black;">convertTo</span> = </span><span style="color: maroon;">"8"</span><span style="color: #000000;"> + <span style="color: black;">convertTo</span>;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">break</span><span style="color: #000000;">;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">case</span><span style="color: #000000;"> </span><span style="color: maroon;">"1001"</span><span style="color: #000000;">:</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span><span style="color: black;">convertTo</span> = </span><span style="color: maroon;">"9"</span><span style="color: #000000;"> + <span style="color: black;">convertTo</span>;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">break</span><span style="color: #000000;">;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">case</span><span style="color: #000000;"> </span><span style="color: maroon;">"1010"</span><span style="color: #000000;">:</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span><span style="color: black;">convertTo</span> = </span><span style="color: maroon;">"A"</span><span style="color: #000000;"> + <span style="color: black;">convertTo</span>;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">break</span><span style="color: #000000;">;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">case</span><span style="color: #000000;"> </span><span style="color: maroon;">"1011"</span><span style="color: #000000;">:</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span><span style="color: black;">convertTo</span> = </span><span style="color: maroon;">"B"</span><span style="color: #000000;"> + <span style="color: black;">convertTo</span>;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span><span style=""></span></span><span style="color: blue;">break</span><span style="color: #000000;">;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">case</span><span style="color: #000000;"> </span><span style="color: maroon;">"1100"</span><span style="color: #000000;">:</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span><span style="color: black;">convertTo</span> = </span><span style="color: maroon;">"C"</span><span style="color: #000000;"> + <span style="color: black;">convertTo</span>;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">break</span><span style="color: #000000;">;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">case</span><span style="color: #000000;"> </span><span style="color: maroon;">"1101"</span><span style="color: #000000;">:</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span><span style="color: black;">convertTo</span> = </span><span style="color: maroon;">"D"</span><span style="color: #000000;"> + <span style="color: black;">convertTo</span>;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">break</span><span style="color: #000000;">;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">case</span><span style="color: #000000;"> </span><span style="color: maroon;">"1110"</span><span style="color: #000000;">:</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span><span style="color: black;">convertTo</span> = </span><span style="color: maroon;">"E"</span><span style="color: #000000;"> + <span style="color: black;">convertTo</span>;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">break</span><span style="color: #000000;">;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">case</span><span style="color: #000000;"> </span><span style="color: maroon;">"1111"</span><span style="color: #000000;">:</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span><span style="color: black;">convertTo</span> = </span><span style="color: maroon;">"F"</span><span style="color: #000000;"> + <span style="color: black;">convertTo</span>;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">break</span><span style="color: #000000;">;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span>}</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span><span style=""></span>}<span style=""> </span></span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="font-size: small;"><span style="" lang="EN-US"><span style="color: #000000;"><span style=""> </span><span style="color: black;">residue</span> = <span style="color: black;">convertFrom</span>.<span style="color: black;">Length</span> % 4;</span><span style="color: green;">//</span></span><span style="">求余数<span lang="EN-US"></span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">if</span><span style="color: #000000;"> (<span style="color: black;">residue</span> != 0)</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span>{</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">for</span><span style="color: #000000;"> (</span><span style="color: blue;">int</span><span style="color: #000000;"> <span style="color: black;">i</span> = 0; <span style="color: black;">i</span> &lt; <span style="color: black;">residue</span>; <span style="color: black;">i</span>++)</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span>{</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span><span style="color: black;">temp</span> += </span><span style="color: teal;">Convert</span><span style="color: #000000;">.<span style="color: black;">ToInt32</span>(<span style="color: black;">convertFrom</span>.<span style="color: black;">Substring</span>(<span style="color: black;">i</span>, 1))</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span>* </span><span style="color: teal;">Convert</span><span style="color: #000000;">.<span style="color: black;">ToInt32</span>(</span><span style="color: teal;">Math</span><span style="color: #000000;">.<span style="color: black;">Pow</span>(2, <span style="color: black;">residue</span> - <span style="color: black;">i</span> - 1));</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span>}</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span>}</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">if</span><span style="color: #000000;"> (<span style="color: black;">temp</span> != 0)</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span>{</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span><span style="color: black;">convertTo</span> = <span style="color: black;">temp</span>.<span style="color: black;">ToString</span>() + <span style="color: black;">convertTo</span>;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span>}</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-align: left;" align="left"><span style="" lang="EN-US"><span style="font-size: small;"><span style=""><span style="color: #000000;"> </span></span><span style="color: blue;">return</span><span style="color: #000000;"> <span style="color: black;">convertTo</span>;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span style="" lang="EN-US"><span style="font-size: small;"><span style="color: #000000;"><span style=""> </span><span style=""></span>}</span></span></span><span style="" lang="EN-US"></span></p>
分享到:
评论

相关推荐

    C# 中2,10,16进制及其ASCII码之间转化

    可以使用 ASCIIEncoding.GetBytes() 方法将 ASCII 字符串转换为十六进制数。例如: ```csharp string s2 = "2Ab 刘"; byte[] ba = System.Text.ASCIIEncoding.Default.GetBytes(s2); StringBuilder sb = new ...

    c#智能进制转换器 十进制数字转换为二进制 ,八进制,十六进制

    在C#编程中,开发一个智能进制转换器可以让我们轻松地将十进制数字转换为二进制、八进制和十六进制。这个任务要求我们实现自定义的算法,而不是依赖内置的函数或库,以确保程序的通用性和不受数字范围限制。 首先,...

    java_十进制数转换为二进制,八进制,十六进制数的算法

    在Java编程语言中,将十进制数转换为二进制、八进制或十六进制是常见的数据处理任务,尤其是在计算机科学与信息技术领域。本文将深入探讨如何使用Java实现这些转换,包括算法原理和具体代码实现。 ### 十进制转二...

    16进制与字符串、字节数组之间的转换

    根据给定的信息,本文将详细解释16进制与字符串、字节数组之间的转换方法,并结合提供的C#代码示例进行深入分析。 ### 一、16进制与整数之间的转换 #### 1.1 二进制转十六进制 在计算机科学中,经常需要将不同进制...

    C#16进制转换10进制源码

    在给定的部分内容中,有以下代码片段展示了如何使用 `Convert` 类中的 `ToInt32` 方法将十六进制字符串转换为十进制整数: ```csharp // 将十六进制字符串 "FF" 转换为十进制整数 Console.WriteLine(Convert.ToInt32...

    c# 字符串处理进制转换

    - **二进制(Binary)到其他进制**:可以使用`Convert.ToInt32(string, int)`方法将二进制字符串转换为十进制整数,然后利用`ToString("X")`或`ToString("D")`将十进制数转换为十六进制或八进制字符串。 - **八...

    C#二进制、八进制、十进制、十六进制相互转换

    本篇将详细讲解如何在C#中进行二进制、八进制、十进制和十六进制之间的转换,以及在Winform环境中实现这一功能。 一、基本概念 1. 二进制(Binary):由0和1组成,是最基础的数字系统,适用于计算机内部数据存储和...

    应用.NET类库中的栈类Stack完成十进制转换成二进制、八进制、十六进制。要求应用 Windows窗体程序设计实现,界面美观,功能完善。

    在本案例中,`Stack`类被用来实现将十进制数转换为二进制、八进制和十六进制的功能。 #### 二、十进制数转换为其他进制数 **1. 基本原理** - **十进制转二进制**: 不断除以2取余数,直到商为0为止,最后将所有...

    字符串转 Ascii数据转换方法函数.cs

    string先转成16进制再转换成ascii ...八进制转换成十六进制 二进制转换成八进制 二进制转换成十进制 二进制转换成十六进制 十六进制转换二进制 十六进制转换八进制 十六进制转换十进制 十六进制转换十进制

    C#进制转换函数(2,8,10,16进制之间的转换)

    C#中,我们可以通过调用`Convert.ToString`方法将一个十进制数转换为二进制、八进制或十六进制字符串表示形式。示例如下: ```csharp int decimalNumber = 69; string binaryString = Convert.ToString(decimal...

    16进制与ASCII互转

    例如,在处理二进制文件或网络通信时,我们可能需要将ASCII字符转换为16进制表示,或者反过来,将16进制数据解析成可读的ASCII字符串。这是因为16进制提供了一种更简洁的方式来显示二进制数据,而ASCII则提供了字符...

    C#进制转换demo

    本文将深入探讨C#中如何进行二进制、八进制、十进制和十六进制之间的转换,以及如何处理字符串和ASCII编码。我们将通过具体的示例代码来理解这些概念。 首先,让我们来看二进制(Binary)转换。二进制是计算机科学...

    winform c# 进制转换

    在C#编程环境中,Winform应用常常用于创建用户界面,而进制转换是计算机科学的基础概念,涉及到二进制(Binary)、八进制(Octal)、十进制(Decimal)和十六进制(Hexadecimal)之间的数值转换。下面将详细阐述如何...

    C# 进制转换(2 8 10 16)进制间任意转换,并输出字符串结果

    本主题将深入探讨如何在二进制(2)、八进制(8)、十进制(10)和十六进制(16)之间进行转换,并且将结果输出为字符串形式。 首先,让我们理解进制的概念。进制是一种数字系统,它定义了使用多少个不同的符号来...

    C#进制转换 可以从任意进制转任意进制

    这个函数可以方便地进行各种进制转换,比如将一个十六进制数转换为八进制: ```csharp string hexNum = "1A"; int octalNum = Convert.ToInt32(hexNum, 16); string octalStr = ConvertBase(octalNum.ToString(), ...

    c#下 2进制、8进制、10进制、16进制...各种进制间的轻松转换

    // 将十进制数42转换为八进制字符串 string hexadecimal = "ABCD"; int decimalFromHex = Convert.ToInt32(hexadecimal, 16); // 将十六进制字符串转换为十进制 ``` 除了这两个主要方法,还有其他方法如`ToByte`,...

    C#进制转换器

    `将十进制数10转换为十六进制字符串"0A"。 3. **转换为十六进制**:对于数值类型,可以使用`ToString("X")`或`ToString("x")`,前者表示大写的十六进制,后者表示小写的十六进制。 4. **转换为二进制和八进制**:...

    进制转换_C#_进制转换_

    在C#这种高级编程语言中,进行进制转换可以方便地处理二进制、八进制、十进制和十六进制等不同数字系统之间的数据交互。本项目是一个专门针对进制转换的小程序,旨在帮助用户便捷地实现任意进制之间的转换。 C#中的...

Global site tag (gtag.js) - Google Analytics