Understanding the use of DWORD
Hello, I am a newbe in the use of VB
My goal is to read a data streaming from a machine...
the streaming is divided in tre main parts,
the first is a 10 byte array that declare the length of the second and third part.
The second one, the header, is a 22 DWORD (*32bit) ( 88 byte ) structured of mixed data types.
I can easly read the value inside this header when the DWORD contains just one information using something like:
Code:
For counter = 0 To 21
For i = 0 To 3
vettore_appoggio(i) = data(10 + i + counter * 4)
Next i
header(counter) = System.BitConverter.ToUInt32(vettore_appoggio, 0)
Next counter
My problem starts because some of these DWORD contains several indipendent informations, for example
DWORD #4 [ channel 2 peaks 31..16] [channel 1 peaks 15..0].
For what I understood the first 16 bits ( so 2 bytes) are used to store the information of the first channel , while the second 16 bits are used for the second channel, I tryed converting the first 2 byte with
System.BitConverter.ToUInt16()
but without success.
Can someone explain me what to do and how these numbers are supposed to be stored?
Thank you so much.
Re: Understanding the use of DWORD
Welcome to the forums. You posted this in the VB6 and earlier section, not the .Net section where it should have been. I've informed the admins so they can move it for you.
Re: Understanding the use of DWORD
Moved To VB.NET (And Added [code]your code goes here[/code] Tags)
Thanks for the heads up LaVolpe :thumb:
Re: Understanding the use of DWORD
From what you describe, the approach looks reasonable. You might be running into problems with the byte order. If you were to look at the two bytes, would you be able to tell whether the bytes have the high byte first or last? Converting will be expecting it in one order, and you may be getting the other order, in which case you would need to swap them.
Re: Understanding the use of DWORD
Yes Shaggy, it works, I did a mess with the counters inside the loop :(
But Now, I have another problem, one of these DWORD contains informations in a single bit, something like "if the bit 31 is 0 the fan is on otherwise it is off"
How can I split a byte in 8 bit?
Thank you again for your help
Re: Understanding the use of DWORD
Use a mask.
Assume you have your byte in a variable called B.
To check bit:
1: If (B And 1) > 0
2: If (B And 2) > 0
3: If (B And 4) > 0
4: If (B And 8) > 0
5: If (B And 16) > 0
6: If (B And 32) > 0
7: If (B And 64) > 0
8: If (B And 128) > 0
So just choose whichever bit you need to look at, and use an AND statment to mask it out.
Re: Understanding the use of DWORD
Quote:
Originally Posted by
lardoso
Yes Shaggy, it works, I did a mess with the counters inside the loop :(
But Now, I have another problem, one of these DWORD contains informations in a single bit, something like "if the bit 31 is 0 the fan is on otherwise it is off"
How can I split a byte in 8 bit?
Thank you again for your help
You might also look at the BitArray class and/or the BitVector32 structure.