vb将字符串显示为二进制数据
vb将字符串显示为二进制数据,这里主要使用向右移位操作,经过测试,移位操作符>>的移位时循环移位的,示例代码如下,在本示例中,尝试修改还可以观察到各种字符编码的宽度
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim thetest As Int16 = 3
Dim thetest1 As UInt16 = 1
Dim mystring As String = Nothing
'thetest1 <<= 15 左移位
'thetest1 = thetest1 * 2 - 2
thetest1 = 1
Dim myBytes() As Byte = System.Text.Encoding.UTF32.GetBytes("中托人")
Dim thstring As String = Nothing
Dim tt As Int32 = 0
For tt = 0 To myBytes.Length - 1
mystring = "+" + mystring
Dim i As Int16 = 0
While (i < 8)
Dim theccd As UInt16 = myBytes(tt)
theccd >>= i
theccd = theccd And thetest1
thstring = theccd.ToString
mystring = thstring + mystring
i += 1
End While
i = 0
mystring = vbCrLf + mystring
Next tt
Label2.Text = mystring
End Sub
End Class