Solved

C Conversion

Posted on 2006-10-31
3
322 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

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…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

910 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now