Results 1 to 11 of 11

Thread: Performing mathematical operations on byte arrays

  1. #1

    Thread Starter
    Member calculus's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    42

    Smile Performing mathematical operations on byte arrays

    Friends,

    Could I have your valuable advice on how to do this in VB6. I am not familiar if VB6 can perform this kind of vector algebra by some preset commands.


    I have 2 long byte arrays :

    ByteArr_X = [0000000011111000000001111]
    ByteArr_Y= [0010010011111000000001111]

    I want to make a new byte array:

    ByteArr_Z

    such that:

    first element of ByteArr_X* 1 + first element of ByteArr_Y *2
    second element of ByteArr_X* 1 + second element of ByteArr_Y *2
    third element of ByteArr_X* 1 + third element of ByteArr_Y *2
    ...
    ...
    ...
    last element of ByteArr_X* 1 + last element of ByteArr_Y *2

    Can VB6 perform vector mathematics, or how does one approach this type of mathematics in VB6?

    Calculus

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

    Re: Performing mathematical operations on byte arrays

    Are you using VB6?

    Clarification: What are the contents of the Byte array? Are each element just a 1 or 0? Or do they have values from 0 to 255? By first element, do you simply mean the entire byte value or are you referencing bits vs bytes?
    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

    Thread Starter
    Member calculus's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    42

    Smile Re: Performing mathematical operations on byte arrays

    Dear LaVolpe,

    First thanks for your help with my earlier problem.

    Yes you are right,each element just a 1 or 0.

    The first element of the first array is 0 , the second is also 0 and so on, sorry, I was using Matlab kind of terminology.

    I have declared the byte arrays in the following manner:

    Dim ByteArr_X() As Byte, ByteArr_Y() As Byte

    So by first element I mean the first value.

    Thanks

    Calculus

  4. #4
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Performing mathematical operations on byte arrays

    Calculus

    You're in great hands with LaVolpe, so I'll try not to step on his toes...
    but, a general question:

    how do you multiply ByteArr_Y by 2 and represent that as a byte?

    eg:

    baX(0) = 0, baY(0) = 0 >> 0*1 + 0*2 = 0 .. baZ(0) = 0
    baX(1) = 0, baY(1) = 0 >> 0*1 + 0*2 = 0 .. baZ(1) = 0
    baX(2) = 0, baY(2) = 1 >> 0*1 + 1*2 = 2 .. baZ(2) = 2 << huh ??
    baX(3) = 0, baY(3) = 0 >> 0*1 + 0*2 = 0 .. baZ(3) = 0

    Spoo

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

    Re: Performing mathematical operations on byte arrays

    You're welcome, regarding previous assistance. We don't always get a thank you, but it makes our day when we do get them.

    You do realize that adding 1 to 1 will be 2. Is that permitted? And if not, what happens to your array when that does occur.

    If values of 2 are no biggie, then your loop might look like this
    Code:
    Dim ByteArr_Z() As Byte
    Dim i As Long
    ReDim ByteArr_Z(LBound(ByteArr_X) To UBound(ByteArr_X))
    For i LBound(ByteArray_X) To UBound(ByteArr_X)
       ByteArr_Z(i) = ByteArray_X(i) + ByteArray_Y(i)
    Next
    Above loop pertains to your addition requirement
    Quote Originally Posted by calculus
    first element of ByteArr_X* 1 + first element of ByteArr_Y *2
    second element of ByteArr_X* 1 + second element of ByteArr_Y *2
    third element of ByteArr_X* 1 + third element of ByteArr_Y *2
    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}

  6. #6

    Thread Starter
    Member calculus's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    42

    Re: Performing mathematical operations on byte arrays

    Thanks Spoo and LaVolpe,

    Firstly, Spoo yes it may seem strange but this is exactly the input required by the device I am trying to operate, basically it wants inputs as a single array of numbers , it then does backwards calculation and gets the binary form for each channel.


    LaVolpe, Thank you very much once again, I will try this out and get back to you in a few days.

    You guys are great.

    Calculus

  7. #7
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Performing mathematical operations on byte arrays

    Calculus

    OK, glad the suggestions were deemed helpful. Two things...

    1. I think my question stemmed from incorrect use of terms bit and byte.
    Natch, a element of a byte array can range in value from 0 to 255, so
    a value of 2 is not a problem (despite my initial balk).

    2. I think LaVolpe omitted the multiplication component in his code..

    Code:
    Dim ByteArr_Z() As Byte
    Dim i As Long
    ReDim ByteArr_Z(LBound(ByteArr_X) To UBound(ByteArr_X))
    For i LBound(ByteArray_X) To UBound(ByteArr_X)
       ByteArr_Z(i) = ByteArray_X(i) + ByteArray_Y(i) * 2
    Next
    .. but I'm sure you both already noticed that, too.

    Look forward to your update in a few days.

    Spoo

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

    Re: Performing mathematical operations on byte arrays

    Quote Originally Posted by Spoo
    2. I think LaVolpe omitted the multiplication component in his code.... but I'm sure you both already noticed that, too.
    I didn't notice my blunder, hopefully calculus did. Thanx
    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}

  9. #9

    Thread Starter
    Member calculus's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    42

    Re: Performing mathematical operations on byte arrays

    Yes I did, thank you both.

    By the way does VB6 allow for bit arrays, kind of curious because that will certainly save a lot of computer memory. If not its fine.

    Thanks

    Calculus

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

    Re: Performing mathematical operations on byte arrays

    No bit arrays. Bits calculations must be performed via bit shifting and capable of handling overflows; there are plenty of posts on this topic and I wouldn't say it is always easy, but challenging would be a good word.
    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}

  11. #11

    Thread Starter
    Member calculus's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    42

    Re: Performing mathematical operations on byte arrays

    I see. Thanks LaVolpe

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