From: mikebres on
I am looking for some help understanding this piece of code.

byteArray(12) = CType((1 >> 16 and 255), Integer)

I'm not a VB.Net programmer and I don't know what the double greater than
symbol means ( >> ) and why the original person is using the And operator
here. I found this code in VB.Net that does what I need to do, except I need
to do it in VBA so I am trying to gain a better understanding of what this is
doing so I can translate it. For background, here is a description of what I
am trying to accomplish.

"For each of the remaining 18 tracking code digits (from left to right, each
of which can range from 0 to 9), multiply the Binary Data Field by 10
decimal, then add the Tracking Code digit."

I believe the piece of code above is where one element of the original
Binary Field is being placed into the byte Array in preparation to be
multiplied by 10.

Also, if you have any references I could study to get a better understanding
of how to use a byte array I would greatly appreciate if you would point me
that way.

Thank You
Mike
From: Family Tree Mike on


"mikebres" wrote:

> I am looking for some help understanding this piece of code.
>
> byteArray(12) = CType((1 >> 16 and 255), Integer)
>
> I'm not a VB.Net programmer and I don't know what the double greater than
> symbol means ( >> ) and why the original person is using the And operator
> here. I found this code in VB.Net that does what I need to do, except I need
> to do it in VBA so I am trying to gain a better understanding of what this is
> doing so I can translate it. For background, here is a description of what I
> am trying to accomplish.
>
> "For each of the remaining 18 tracking code digits (from left to right, each
> of which can range from 0 to 9), multiply the Binary Data Field by 10
> decimal, then add the Tracking Code digit."
>
> I believe the piece of code above is where one element of the original
> Binary Field is being placed into the byte Array in preparation to be
> multiplied by 10.
>
> Also, if you have any references I could study to get a better understanding
> of how to use a byte array I would greatly appreciate if you would point me
> that way.
>
> Thank You
> Mike

The code is pulling the third byte only out of a four byte integer. The
code "1 >> 16" means to move the bits 16 positions (two bytes) right.
"And"ing by 255 means that any bits set above teh first byte will be set to
zero. Therefore, if you have the following in memory for the integer:

|byte4|byte3|byte2|byte1|

After Shift:
|zeros|zeros|byte4|byte3|

After And'ing
|zeros|zeros|zeros|byte3|

Mike

From: mikebres on
Okay, so the >> symbol is a bit shift right. Thank you!

"Family Tree Mike" wrote:

>
>
> "mikebres" wrote:
>
> > I am looking for some help understanding this piece of code.
> >
> > byteArray(12) = CType((1 >> 16 and 255), Integer)
> >
> > I'm not a VB.Net programmer and I don't know what the double greater than
> > symbol means ( >> ) and why the original person is using the And operator
> > here. I found this code in VB.Net that does what I need to do, except I need
> > to do it in VBA so I am trying to gain a better understanding of what this is
> > doing so I can translate it. For background, here is a description of what I
> > am trying to accomplish.
> >
> > "For each of the remaining 18 tracking code digits (from left to right, each
> > of which can range from 0 to 9), multiply the Binary Data Field by 10
> > decimal, then add the Tracking Code digit."
> >
> > I believe the piece of code above is where one element of the original
> > Binary Field is being placed into the byte Array in preparation to be
> > multiplied by 10.
> >
> > Also, if you have any references I could study to get a better understanding
> > of how to use a byte array I would greatly appreciate if you would point me
> > that way.
> >
> > Thank You
> > Mike
>
> The code is pulling the third byte only out of a four byte integer. The
> code "1 >> 16" means to move the bits 16 positions (two bytes) right.
> "And"ing by 255 means that any bits set above teh first byte will be set to
> zero. Therefore, if you have the following in memory for the integer:
>
> |byte4|byte3|byte2|byte1|
>
> After Shift:
> |zeros|zeros|byte4|byte3|
>
> After And'ing
> |zeros|zeros|zeros|byte3|
>
> Mike
>