注册 登录
电子工程世界-论坛 返回首页 EEWORLD首页 频道 EE大学堂 下载中心 Datasheet 专题
程序天使的个人空间 https://home.eeworld.com.cn/space-uid-43048.html [收藏] [复制] [分享] [RSS]
日志

实现十进制和二,八,十六进制之间的相互转换

已有 993 次阅读2008-5-30 10:37

最近写了两个小程序,涉及到十进制和十六进制之间的转换,就顺便把

相关的知识总结一哈~~~

    使用Convert类的ToInt32()fang方法把二,八,十六进制数转换为十进制,

Code:

 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim mydim1 As Integer
        Dim mydim2 As Integer
        Dim mydim3 As Integer
        Dim mybinary As String = "1111"
        Dim myoctal As String = "17"
        Dim myhex As String = "f"
        mydim1 = Convert.ToInt32(mybinary, 2).ToString()
        mydim2 = Convert.ToInt32(myoctal, 8).ToString()
        mydim3 = Convert.ToInt32(myhex, 16).ToString()
        Label1.Text = "MyBinary=1111转换为十进制:" & mydim1
        Label2.Text = "MyOctal=17转换为十进制:" & mydim2
        Label3.Text = "Myhex=f转换为十进制:" & mydim3
    End Sub

可以使用Convert类的ToString()方法把十进制转换为二,八,十六进制数;

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim mydim As Integer = 15
        Dim mybinary As String
        Dim myoctal As String
        Dim myhex As String
        mybinary = Convert.ToString(mydim, 2).ToString()
        myoctal = Convert.ToString(mydim, 8).ToString()
        myhex = Convert.ToString(mydim, 16).ToString()
        Label1.Text = "十进制15转换为二进制:MyBinary=" & mybinary
        Label2.Text = "十进制15转换为八进制:MyOctal=" & myoctal
        Label3.Text = "十进制15转换为十六进制:Myhex=" & myhex

  End Sub

 

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册

热门文章