Results 1 to 7 of 7

Thread: Understanding the use of DWORD

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2010
    Posts
    2

    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.
    Last edited by Hack; Jun 16th, 2010 at 10:39 AM. Reason: Added Code Tags

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    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.
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    New Member
    Join Date
    Jun 2010
    Posts
    2

    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

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    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.
    My usual boring signature: Nothing

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Understanding the use of DWORD

    Quote Originally Posted by lardoso View Post
    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width