Home All Groups Group Topic Archive Search About

Byte to int Conversion ..??

Author
18 Apr 2006 11:01 AM
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

Author
18 Apr 2006 11:16 AM
Ken Tucker [MVP]
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
-----------------------
Show quoteHide quote
"Sanjay" <Sanjayrv***@gmail.com> wrote in message
news:1145358108.933887.235320@z34g2000cwc.googlegroups.com...
> 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
>
Author
18 Apr 2006 12:03 PM
Larry Lard
Sanjay wrote:
> 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.

--
Larry Lard
Replies to group please
Author
18 Apr 2006 12:07 PM
Herfried K. Wagner [MVP]
"Sanjay" <Sanjayrv***@gmail.com> schrieb:
>  Is this a legal to convert  from byte array to int array..
>     CopyMemory intAudio(0), byteAudio(0), 4096

Check out the 'BitConverter' class.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
18 Apr 2006 5:46 PM
Mattias Sjögren
>  Is this a legal to convert  from byte array to int array..

Use System.Buffer.BlockCopy()


Mattias

--
Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.