473,396 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Byte to int Conversion ..??

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

Apr 18 '06 #1
4 1605
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" <Sa*********@gmail.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.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

Apr 18 '06 #2

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

Apr 18 '06 #3
"Sanjay" <Sa*********@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/>
Apr 18 '06 #4
> 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.
Apr 18 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Bryan Parkoff | last post by:
I have two variables: "char A" and "short B". I can be able to convert from A to B using explicit case conversion with no problem like "B = short (A);". Right now, I have two variables: "char T"...
3
by: mailar | last post by:
HI, Can anyone tell me how is a multi_byte to single byte and vice versa conversion done in DB2. It would be great even if someone can tell me how Oracle does it? Oracle already has functions...
2
by: Jesse Engle | last post by:
i'm learning how to do some basic low-level network programming. the site i'm reading talks about "network byte order" and "host byte order". the thing is, it doesn't give an explanation as to what...
11
by: QQ | last post by:
I know a char is 2 bytes, the conversion is like byte byte_array = new byte; //Allocate double mem as that of char then for each char do byte = (byte) char & 0xff byte = (byte)( char >> 8 &...
1
by: Wasim Akram | last post by:
Hi, I have a field "Month" in my SQL server table. The type of this field is "tinyint". Now what I am doing in the code is using DataRow to read this field in a 'int' variable. int month...
4
by: Dennis Myrén | last post by:
Hi. Is there a way to utilize the great primitive data type formatting routines available in .NET without working with strings? I want a byte directly rather than a string. I think it is...
3
by: megan | last post by:
I can easily get my byte array into the SqlBinary Sql servr field. getting it out again is more difficult. SqlBinary myBin = myBinaryObject; // object from SQL server field. byte b= myBin ; ...
25
by: Charles Law | last post by:
I thought this was going to be straight forward, given the wealth of conversion functions in .NET, but it is proving more convoluted than imagined. Given the following <code> Dim ba(1) As...
16
by: Hugh Janus | last post by:
Hi all, I am using the below functions in order to convert strings to bytes and vice versa. I totally ans shamefully stole these functions from this group btw! Anyway, they work great but as...
5
by: jeremyje | last post by:
I'm writing some code that will convert a regular string to a byte for compression and then beable to convert that compressed string back into original form. Conceptually I have.... For...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.