开发者

What's the easiest way to convert an Int32's bytes to String?

开发者 https://www.devze.com 2023-01-06 00:28 出处:网络
D开发者_如何学Cim intChunkId As Integer = &H4D546864 Dim strChunkId As String = \"MThd\" Dim easiestWay = GetString(intChunkId)
D开发者_如何学Cim intChunkId As Integer = &H4D546864   
Dim strChunkId As String = "MThd"

Dim easiestWay = GetString(intChunkId)

easiestWay should now equal strChunkId.


Dim bytes As Byte() = BitConverter.GetBytes(intChunkId)
Dim strChunkId As String = Encoding.ASCII.GetString(bytes)

A couple of points:

  1. This assumes the bytes in the integer are all the ASCII range (the ones in your example are, but they might not always be: in that case, you can use Encoding.Default.)
  2. My VB is a bit rusty, I'm not sure I got the declaration of arrays right...
0

精彩评论

暂无评论...
验证码 换一张
取 消