Byte to int Conversion ..??

  • Thread starter Thread starter Sanjay
  • Start date Start date
S

Sanjay

Hi
Is this a legal to convert from byte array to int array..
CopyMemory intAudio(0), byteAudio(0), 4096
Please help me out
thanks
sanjay
 
Hi,

If you are using vs 2005 this will work.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim apf() As Byte = { _
27, 32, 99, 147, 7, 141}

Trace.WriteLine("")
For Each b As Byte In apf
trace.WriteLine(b)
Next

Dim ap() As Integer = Array.ConvertAll(apf, _
New Converter(Of Byte, Integer)(AddressOf ByteToInteger))

Trace.WriteLine("")
For Each p As Integer In ap
Trace.WriteLine(p)
Next

End Sub

Public Shared Function ByteToInteger(ByVal pf As Byte) _
As Integer

Return CInt(pf)
End Function

Ken
 
Sanjay said:
Hi
Is this a legal to convert from byte array to int array..
CopyMemory intAudio(0), byteAudio(0), 4096
Please help me out

Array.Copy byteAudio, intAudio, 4096

Because Byte can be automatically converted to Integer, you don't need
a converison function.
 
Sanjay said:
Is this a legal to convert from byte array to int array..
CopyMemory intAudio(0), byteAudio(0), 4096

Check out the 'BitConverter' class.
 
Is this a legal to convert from byte array to int array..

Use System.Buffer.BlockCopy()


Mattias
 
Back
Top