老师参与

这个进制转换为什么得不到正确结果?转换成十六进制怎么修改?

ldhzx2949 发表于2018年06月13日
<p>Public Class Form1</p><p>&nbsp; &nbsp; Function tran$(ByVal d%, ByVal r%)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; If d = 0 Then</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tran = &quot;&quot;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; Else</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tran = tran(d / r, r) &amp; (d Mod r)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; End If</p><p>&nbsp; &nbsp; End Function</p><p>&nbsp; &nbsp; Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click</p><p>&nbsp; &nbsp; &nbsp; &nbsp; Dim d = Val(TextBox1.Text)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; Dim r = Val(TextBox2.Text)</p><p>&nbsp; &nbsp; &nbsp; &nbsp; Label4.Text = tran(d,r)</p><p>&nbsp; &nbsp; End Sub</p><p>End Class</p><p><br ></p>
1 回复

    1楼

  • 龚沛曾 发表于2018年06月20日
    0 | 0 | 举报
    <p>你应该用整除:tran = tran(d \ r, r) &amp; (d Mod r)</p><p>转换成16进制要考虑余数大于9时转换成对应的A~F. 这个问题请你自己思考了。</p>
    龚沛曾 发表于2018年06月20日
    添加评论