?
Solved

C Conversion

Posted on 2006-10-31
3
Medium Priority
?
358 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
adg080898 earned 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Suggested Courses

770 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