By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,101 Members | 1,360 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,101 IT Pros & Developers. It's quick & easy.

C# to VB.NET Conversion

P: n/a
I'm playing around with converting some C# code to VB.NET as a learning
exercise and I'm running into a little confussion for my lack of
understanding some C# syntax.

The C# code is:
public const int LOCSIG = 'P' | ('K' << 8) | (3 <<16) | (4 << 24)

Can anybody explain to me what this is doing and possibly give me a VB.NET
equivalent?
I'm confused about the characters 'P' & 'K' as part of an integer constant
and what the pipes are along with what << means.

TIA,
-Matt
Nov 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
In college, we used to challenge eachother. We'd give eachother blocks of
really really obscure C code and see if the other person could figure out
what it does without running it. The author of this bit of code must have
attended my school :-)

The pipes are bitwise OR. The << operator is a logical left shift. In C,
placing a character between single quotes is the same as getting the numeric
value of the character. see http://www.asciitable.com/

So, this expression is simply an integer value created using a series of
rather obtuse binary expressions.
public const int LOCSIG = 'P' | ('K' << 8) | (3 <<16) | (4 << 24) which is equal to 0000 0100 0000 0011 0100 1001 0101 0000
or hex 0403 4B50

HTH,

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Matthew Hood" <Dr***********@Yahoo.com> wrote in message
news:OZ**************@TK2MSFTNGP12.phx.gbl... I'm playing around with converting some C# code to VB.NET as a learning
exercise and I'm running into a little confussion for my lack of
understanding some C# syntax.

The C# code is:
public const int LOCSIG = 'P' | ('K' << 8) | (3 <<16) | (4 << 24)

Can anybody explain to me what this is doing and possibly give me a VB.NET
equivalent?
I'm confused about the characters 'P' & 'K' as part of an integer constant
and what the pipes are along with what << means.

TIA,
-Matt

Nov 21 '05 #2

P: n/a
Public Const LOCSIG As Int32=AscW("P"c)Or(AscW("K"c)<<8)Or(3<<16)Or(4<<24 )

Characters need to be converted to their ASCII value before they can be used
in this kind of equation.

| = Or

<< = Binary Shift to the Left
= Binary Shift to the Right

Example table to help explain Binary Shift.

Binary (Base 2) | Decimal Equivelant | Alternative Equation
----------------------------------------------------------------
001010 << 1 = 010100 10 << 1 = 20 10 * (2 * 1) = 20
001011 << 1 = 010110 11 << 1 = 22 11 * (2 * 1) = 22
001010 << 2 = 101000 10 << 2 = 40 10 * (2 * 2) = 40
001011 << 2 = 101100 11 << 2 = 44 11 * (2 * 2) = 44

1010 >> 1 = 0101 10 >> 1 = 5 10 \ (2 * 1) = 5
1011 >> 1 = 0101 11 >> 1 = 5 11 \ (2 * 1) = 5
1010 >> 2 = 0010 10 >> 2 = 2 10 \ (2 * 2) = 2
1011 >> 2 = 0010 11 >> 2 = 2 11 \ (2 * 2) = 2
----------------------------------------------------------------

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Matthew Hood" <Dr***********@Yahoo.com> wrote in message
news:OZ**************@TK2MSFTNGP12.phx.gbl... I'm playing around with converting some C# code to VB.NET as a learning
exercise and I'm running into a little confussion for my lack of
understanding some C# syntax.

The C# code is:
public const int LOCSIG = 'P' | ('K' << 8) | (3 <<16) | (4 << 24)

Can anybody explain to me what this is doing and possibly give me a VB.NET
equivalent?
I'm confused about the characters 'P' & 'K' as part of an integer constant
and what the pipes are along with what << means.

TIA,
-Matt

Nov 21 '05 #3

P: n/a
That definately helps! Thanks a lot!

"Matthew Hood" <Dr***********@Yahoo.com> wrote in message
news:OZ**************@TK2MSFTNGP12.phx.gbl...
I'm playing around with converting some C# code to VB.NET as a learning
exercise and I'm running into a little confussion for my lack of
understanding some C# syntax.

The C# code is:
public const int LOCSIG = 'P' | ('K' << 8) | (3 <<16) | (4 << 24)

Can anybody explain to me what this is doing and possibly give me a VB.NET
equivalent?
I'm confused about the characters 'P' & 'K' as part of an integer constant
and what the pipes are along with what << means.

TIA,
-Matt

Nov 21 '05 #4

P: n/a
Matthew,

You never know if you still see this, will be handy

Code C# and VB
http://www.harding.edu/USER/fmccown/...omparison.html

Language compare
http://msdn.microsoft.com/library/en...quivalents.asp

I hope this helps?

Cor
Nov 21 '05 #5

P: n/a
Those sites will do quite nicely.
Thanks Cor.

"Cor Ligthert" <no************@planet.nl> wrote in message
news:uE**************@TK2MSFTNGP12.phx.gbl...
Matthew,

You never know if you still see this, will be handy

Code C# and VB
http://www.harding.edu/USER/fmccown/...omparison.html

Language compare
http://msdn.microsoft.com/library/en...quivalents.asp

I hope this helps?

Cor

Nov 21 '05 #6

P: n/a
It appears as if you are examining code that decompresses .zip files as
the bytes you show represent the header of a zip file.

You might download the code for the ISharpZip library and see how they
handle that code it may also help your translation to VB code.

Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.