zoukankan      html  css  js  c++  java
  • 【.Net】2、8、16进制转换

    
    
        Private Function Asc2String(ByVal str As String) As String
            Dim StrDesc As System.String = String.Empty
            If str = String.Empty OrElse str.Length Mod 2 <> 0 Then
                MessageBox.Show("Input string error.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                Asc2String = String.Empty
                Exit Function
            End If
            For i As System.Int32 = 0 To str.Length() - 1 Step 2
                Dim s As System.String = Mid(str, i + 1, 2)
                Dim num As System.Int32 = Convert.ToInt32(s, 16)
                If num < 0 OrElse num > 256 Then
                    MessageBox.Show(String.Format("Input number {0} error.", num.ToString()), "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                    Asc2String = String.Empty
                    Exit Function
                End If
                StrDesc = StrDesc & ChrW(num)
            Next
            Asc2String = StrDesc.Trim
        End Function

    Public Shared Function ToInt32(ByVal value As String, ByVal fromBase As Integer) As Integer

    成员属于: System.Convert
    摘要:
    将指定基数的数字的 System.String 表示形式转换为等效的 32 位有符号整数。

    参数:
    value: 包含数字的 System.String。
    fromBase: value 中数字的基数,它必须是 2、8、10 或 16。

    返回值:
    等效于 value 中的数字的 32 位有符号整数。 - 或 - 如果 value 为 null,则为零。

    异常:
    System.ArgumentException: fromBase 不是 2、8、10 或 16。 - 或 - value,它表示一个非 10 为基的有符号数,前面带一个负号。
    System.FormatException: value 包含的一个字符不是 fromBase 指定的基中的有效数字。如果 value 中的第一个字符无效,异常消息则指示没有可转换的数字;否则,该消息将指示 value 包含无效的尾随字符。
    System.OverflowException: value,它表示一个非 10 为基的有符号数,前面带一个负号。 - 或 - 返回值小于 System.Int32.MinValue 或大于 System.Int32.MaxValue。

        Private Function String2Asc(ByVal str As String) As String
            Dim StrDesc As System.String = String.Empty
            For i As System.Int32 = 0 To str.Length() - 1
                Dim s As System.Char = str(i)
                StrDesc = StrDesc & Convert.ToString(AscW(s), 16)
            Next
        End Function

    Public Shared Function ToString(ByVal value As Integer, ByVal toBase As Integer) As String
    成员属于: System.Convert
    摘要:
    将 32 位有符号整数的值以指定的基数转换为它的等效 System.String 表示形式。

    参数:
    value: 32 位有符号整数。
    toBase: 返回值的基数,必须是 2、8、10 或 16。

    返回值:
    以 toBase 为基数的 value 的 System.String 表示形式。

    异常:
    System.ArgumentException: toBase 不是 2、8、10 或 16。

  • 相关阅读:
    x32dbg之AttachHelper插件
    x32dbg插件之APIInfo
    x32dbg之Scylla脱壳插件
    x32dbg插件之strongOD(又名SharpOD)
    x32dbg新型插件之loli(萝莉)
    7 个超棒的监控工具
    成为程序员前需要做的10件事
    改良程序的11个技巧
    旧衣物捐献地址和注意事项
    一件衣服好不好,看看标签就知道
  • 原文地址:https://www.cnblogs.com/fjfjfjfjfjfj/p/3335646.html
Copyright © 2011-2022 走看看