Solved

C to VB.Net conversion

Posted on 2006-10-29
7
214 Views
Last Modified: 2010-04-15
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
0
Comment
Question by:IAJWDDIY
  • 3
  • 2
  • 2
7 Comments
 
LVL 37

Assisted Solution

by:momi_sabag
momi_sabag earned 400 total points
ID: 17828749
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
 

Author Comment

by:IAJWDDIY
ID: 17828865
So if I write in the code S1(1) then would it be subsituted with (((1&2)>>1) | ((1&1)<<2))

Thank you.
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 100 total points
ID: 17828893
   Function S1(ByVal a As Integer) As Integer
        Return ((a And 2) >> 1) Or ((a And 1) << 2)
    End Function
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 48

Expert Comment

by:AlexFM
ID: 17828904
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
 
LVL 37

Expert Comment

by:momi_sabag
ID: 17828910
the answer for your question is yes
s1(1) would be subsituted with (((1&2)>>1) | ((1&1)<<2))
0
 

Author Comment

by:IAJWDDIY
ID: 17828952
Thank you both, much appreciated !
0
 

Author Comment

by:IAJWDDIY
ID: 17828956
Sorry just noticed I got the Accepted/Assisted the wrong way round, hope I got the points right.
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question