PC Review


Reply
Thread Tools Rate Thread

Byte Array Question

 
 
mikebres
Guest
Posts: n/a
 
      4th May 2010
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
 
Reply With Quote
 
 
 
 
Family Tree Mike
Guest
Posts: n/a
 
      4th May 2010


"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

 
Reply With Quote
 
mikebres
Guest
Posts: n/a
 
      6th May 2010
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
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I convert a ASCII Byte Array, to another Byte Array Russell Mangel Microsoft Dot NET Framework 2 2nd Feb 2005 06:01 PM
Re: Byte Array to Printable String to Byte Array Jon Skeet [C# MVP] Microsoft Dot NET 0 4th Aug 2004 01:53 PM
How to Convert Binary Coded Hex Byte Array to Byte Charles Law Microsoft VB .NET 25 2nd Jun 2004 02:21 PM
Byte array to string and back - newbie question =?Utf-8?B?cG9wc292eUBydXNtZXguY29t?= Microsoft Dot NET Framework 2 5th Feb 2004 07:47 PM
Convert native byte array (pointer) to managed byte[] Dave Microsoft Dot NET 1 13th Aug 2003 05:08 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:46 PM.