Solved

C Conversion

Posted on 2006-10-31
3
332 Views
Last Modified: 2010-04-15
Hello,

I need to convert the following line of code to VB.Net, can anyone explain the syntax please?



next_A1 = next_A1 ^ D ^ ((j % 2) ? in2 : in1);

0
Comment
Question by:IAJWDDIY
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
adg080898 earned 500 total points
ID: 17846147
^ is a bitwise xor operator. For example, a ^ b will toggle in 'a' any bits set in 'b'.

% is the modulus operator. a % b returns the remainder of dividing 'a' by 'b'.

? selects between two expressions. (a ? b : c) means "if a is true (nonzero), the value of the expression is b, otherwise (a is false or zero), the value of the expression is c.

I don't know VB.net, but this should get you close enough:

// pseudo basic conversion of "next_A1 = next_A1 ^ D ^ ((j % 2) ? in2 : in1);"

tmp = next_A1
    // The following evaluates "next_A1 ^ D"
tmp = result XOR D
    // The following evaluates "j % 2"
tmp2 = j MOD 2
    // The following evaluates ((j % 2) ? in2 : in1)
if tmp2 <> 0
  tmp3 = in2
else
  tmp3 = in1
endif
   // The following does the final xor
result = result XOR tmp3
next_A1 = result

--------------------------------------
Here is a more compact way:

if (j MOD 2) <> 0
  next_A1 = next_A1 XOR D XOR in2
else
  next_A1 = next_A1 XOR D XOR in1
endif


0
 

Author Comment

by:IAJWDDIY
ID: 17846323

Thank you.

0
 
LVL 8

Expert Comment

by:adg080898
ID: 17846342
My pleasure.
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Test against App 49 137
C++ finding a sting in a char* string from a text file 3 108
xamarin c# deserialize Json containing nested object 2 91
Computer slow / BSOD 10 59
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

774 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