C to VB.Net conversion

Hi,

I'm trying to convert some C code into VB.Net, can anyone explain in simple terms the code below?

Thank you.

#define S1(a) (((a&2)>>1) | ((a&1)<<2))
#define S2(a) (((a&2)>>0) | ((a&1)<<3))
#define S3(a) (((a&2)>>1) | ((a&1)<<2))
#define S4(a) (((a&2)>>0) | ((a&1)<<3))
#define S5(a) (((a&2)>>1) | ((a&1)<<2))
#define S6(a) (((a&2)>>0) | ((a&1)<<3))
#define S7(a) a
IAJWDDIYAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
AlexFMConnect With a Mentor Commented:
   Function S1(ByVal a As Integer) As Integer
        Return ((a And 2) >> 1) Or ((a And 1) << 2)
    End Function
0
 
momi_sabagConnect With a Mentor Commented:
hi

this is an inline macro definitions
any time someone writes in the code S1(x) then it is subsituted with (((x&2)>>1) | ((x&1)<<2))

in order to implement it in vb.net (if there are no macros) you can just write a method that does the exact same thing and call it everytime you see the S1(x) text in the code

the & is an and bit operation,
the >> and << are shifting the bits right and left,
if you don't have a shifting operation in vb you can just multiply be a power of 2
shift left (<<) by x is the same as multiply by 2 in the power of x
shift right (>>) by x is the same as dividing by 2 in the power of x

momi sabag
0
 
IAJWDDIYAuthor Commented:
So if I write in the code S1(1) then would it be subsituted with (((1&2)>>1) | ((1&1)<<2))

Thank you.
0
The Firewall Audit Checklist

Preparing for a firewall audit today is almost impossible.
AlgoSec, together with some of the largest global organizations and auditors, has created a checklist to follow when preparing for your firewall audit. Simplify risk mitigation while staying compliant all of the time!

 
AlexFMCommented:
Make other functions by the same way. The simplest case is S7:

   Function S7(ByVal a As Integer) As Integer
        Return a
    End Function

You can write function with two additioal parameters if you want, but writing functions S1-S7 allows to translate C code to VB easily, which looks better.
0
 
momi_sabagCommented:
the answer for your question is yes
s1(1) would be subsituted with (((1&2)>>1) | ((1&1)<<2))
0
 
IAJWDDIYAuthor Commented:
Thank you both, much appreciated !
0
 
IAJWDDIYAuthor Commented:
Sorry just noticed I got the Accepted/Assisted the wrong way round, hope I got the points right.
0
All Courses

From novice to tech pro — start learning today.