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
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?
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
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
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
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
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
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 :o
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
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.
Re: Performing mathematical operations on byte arrays