We help IT Professionals succeed at work.

# C Conversion

on
Medium Priority
374 Views
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);

Comment
Watch Question

## View Solution Only

Commented:
^ 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

Not the solution you were looking for? Getting a personalized solution is easy.

Commented:

Thank you.

Commented:
My pleasure.
Access more of Experts Exchange with a free account
##### Thanks for using Experts Exchange.

Limited access with a free account allows you to:

• View three pieces of content (articles, solutions, posts, and videos)
• Ask the experts questions (counted toward content limit)
• Customize your dashboard and profile