|
-
Jan 25th, 2004, 08:32 AM
#1
Thread Starter
Member
Byte array to Integer conversion
Ok, I can do this by multipling up each byte from left to right but...
I have an byte array and I want to extract a 4-byte Integer value from it, e.g.
Dim Data() = {0,0,1,9} = 265 as an Integer
What I want is simply to turn that array into a Dim I as Integer = the value of that array of data.
Surely there is a simply way to convert this... since the data is in the actual format used by an Integer anyway!
In pratice the Integer data will be within an array somewhere however - i.e. it wont just be a 4 byte array like the above example.
Can't for the life of me see how to do this though...
Anyone care to....
-
Jan 25th, 2004, 02:48 PM
#2
Frenzied Member
here is a byte array to char[]
it might get u somewhere
private char[] EncodeBytesToChars(byte[] data)
{
System.Text.Encoding encoding = System.Text.Encoding.Unicode;
return encoding.GetChars(data);
}
-
Jan 25th, 2004, 04:29 PM
#3
how is this?
VB Code:
Dim Data() As Byte = {0, 0, 1, 9} ' 256
Dim intValue As Integer
Data.Reverse(Data)
intValue = BitConverter.ToInt32(Data, 0)
MsgBox(intValue)
Tips:
- Google is your friend! Search before posting!
- Name your thread appropriately... "I Need Help" doesn't cut it!
- Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
- Allways Include the Name and Line of the Exception (if one is occuring!)
- If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)
If you think I was helpful, rate my post  IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|