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
Solved

C Conversion

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

Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

Question has a verified solution.

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

Suggested Solutions

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
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…
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.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops 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