【问题标题】:Convert BigInterger to Hex string representaion将 BigInteger 转换为十六进制字符串表示
【发布时间】:2018-12-12 10:16:29
【问题描述】:

我有 16 个字节的字符串,我向左移动,在我向左移动后,我试图在 RichTextbox 中显示结果:

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
    Dim positiveString As String = "00082B002C421A21B630B934B7B71C9A99"
    Dim posBigInt As BigInteger = 0
    posBigInt = BigInteger.Parse(positiveString, System.Globalization.NumberStyles.AllowHexSpecifier)
     posBigInt = (posBigInt << 1)
    RichTextBox1.Text = Hex(posBigInt.ToString)
End Sub
Public Function StrToHex(ByRef Data As String) As String
    Dim sVal As String
    Dim sHex As String = ""
    While Data.Length > 0
        sVal = Conversion.Hex(Strings.Asc(Data.Substring(0, 1).ToString()))
        Data = Data.Substring(1, Data.Length - 1)
        sHex = sHex & sVal
    End While
    Return sHex
End Function

StrToHex 函数给了我错误的输出,如果我尝试 Hex(posBigInt.ToString) 给我正确的输出,如果值适合 uint64,因此 Hex() 不能适合 biginterger

【问题讨论】:

    标签: string vb.net hex biginteger


    【解决方案1】:

    看起来像这样(“X”)做的事情:

    RichTextBox1.Text = posBigInt.ToString("X")
    

    在关于 biginterger 的 c# 线程上找到它:BigInteger to Hex/Decimal/Octal/Binary strings?

    【讨论】:

    • 它输出“082B002C421A21B630B934B7B71C9A99”所以它跳过第一个00,也许有人知道如何处理它?
    • 第一个00 对实际数字没有影响,因此不包括在内。你可以在前面加上你想要多少个零,它们仍然不会改变任何东西。为什么要包括一些在那里没有什么区别的东西? :)
    • @VisualVincent 我对该代码有疑问,我正在更新问题,你能看一下吗?
    • 实际上生病了创建新主题
    猜你喜欢
    • 1970-01-01
    • 2017-05-16
    • 2018-01-31
    • 2018-01-22
    • 1970-01-01
    • 2013-02-07
    • 2019-06-30
    • 2014-12-05
    相关资源
    最近更新 更多