String到Hex和Hex到String

时间:2017-05-28 18:21:51

标签: vb.net hex

我能够将我的字符串转换为十六进制值但无法执行相反的方法:

Public Function StringToHex(_str$)
    Return BitConverter.ToString(Convert.FromBase64String(_str$))
End Function

Public Function HexToString(_str$)
  'could not do this
End Function

Private Sub Button55_Click(sender As Object, e As EventArgs) Handles 
Button55.Click
   lblStatus.Text = StringToHex("mankat236598")
   'result : 99-A9-E4-6A-DD-B7-EB-9F-7C

   lblInfo.Text = HexToString( lblStatus.Text)
    'i want result : mankat236598
End Sub

1 个答案:

答案 0 :(得分:2)

由于您的格式字符串表示为" 00-00-00",您需要转换" 00"等到字节。您可以在执行此操作时跳过破折号:

>>> float("0.99999999999999999")
1.0