开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜