Solved

C to VB.Net conversion

Posted on 2006-10-30
5
204 Views
Last Modified: 2010-04-15
Hello,

Can anyone explain the following code in C to help me try to translate to VB.Net?

The define part I understand - someone kindly explained this to me yesterday.

Thank you.

#define S1(a) (((a&2)>>1) | ((a&1)<<2))
#define S2(a) (((a&2)>>0) | ((a&1)<<3))
#define S3(a) (((a&2)>>1) | ((a&1)<<2))
#define S4(a) (((a&2)>>0) | ((a&1)<<3))
#define S5(a) (((a&2)>>1) | ((a&1)<<2))
#define S6(a) (((a&2)>>0) | ((a&1)<<3))
#define S7(a) a

static const int x[] = {
  S1(2),S1(0),S1(1),S1(1),S1(2),S1(3),S1(3),S1(0),
  S1(3),S1(2),S1(2),S1(0),S1(1),S1(1),S1(0),S1(3),
  S1(0),S1(3),S1(3),S1(0),S1(2),S1(2),S1(1),S1(1),
  S1(2),S1(2),S1(0),S1(3),S1(1),S1(1),S1(3),S1(0)
  };
static const int x[] = {
  S2(3),S2(1),S2(0),S2(2),S2(2),S2(3),S2(3),S2(0),
  S2(1),S2(3),S2(2),S2(1),S2(0),S2(0),S2(1),S2(2),
  S2(3),S2(1),S2(0),S2(3),S2(3),S2(2),S2(0),S2(2),
  S2(0),S2(0),S2(1),S2(2),S2(2),S2(1),S2(3),S2(1)
  };
static const int x[] = {
  S3(2),S3(0),S3(1),S3(2),S3(2),S3(3),S3(3),S3(1),
  S3(1),S3(1),S3(0),S3(3),S3(3),S3(0),S3(2),S3(0),
  S3(1),S3(3),S3(0),S3(1),S3(3),S3(0),S3(2),S3(2),
  S3(2),S3(0),S3(1),S3(2),S3(0),S3(3),S3(3),S3(1)
  };
static const int x[] = {
  S4(3),S4(1),S4(2),S4(3),S4(0),S4(2),S4(1),S4(2),
  S4(1),S4(2),S4(0),S4(1),S4(3),S4(0),S4(0),S4(3),
  S4(1),S4(0),S4(3),S4(1),S4(2),S4(3),S4(0),S4(3),
  S4(0),S4(3),S4(2),S4(0),S4(1),S4(2),S4(2),S4(1)
  };
static const int x[] = {
  S5(2),S5(0),S5(0),S5(1),S5(3),S5(2),S5(3),S5(2),
  S5(0),S5(1),S5(3),S5(3),S5(1),S5(0),S5(2),S5(1),
  S5(2),S5(3),S5(2),S5(0),S5(0),S5(3),S5(1),S5(1),
  S5(1),S5(0),S5(3),S5(2),S5(3),S5(1),S5(0),S5(2)
  };
static const int x[] = {
  S6(0),S6(1),S6(2),S6(3),S6(1),S6(2),S6(2),S6(0),
  S6(0),S6(1),S6(3),S6(0),S6(2),S6(3),S6(1),S6(3),
  S6(2),S6(3),S6(0),S6(2),S6(3),S6(0),S6(1),S6(1),
  S6(2),S6(1),S6(1),S6(2),S6(0),S6(3),S6(3),S6(0)
  };
static const int x[] = {
  S7(0),S7(3),S7(2),S7(2),S7(3),S7(0),S7(0),S7(1),
  S7(3),S7(0),S7(1),S7(3),S7(1),S7(2),S7(2),S7(1),
  S7(1),S7(0),S7(3),S7(3),S7(0),S7(1),S7(1),S7(2),
  S7(2),S7(3),S7(1),S7(0),S7(2),S7(3),S7(0),S7(2)
  };
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
  • 2
5 Comments
 
LVL 45

Accepted Solution

by:
Kent Olsen earned 500 total points
ID: 17834544
Hi IAJWDDIY,

All of the #define statements are creating macros.  Looking at the first one:

#define S1(a) (((a&2)>>1) | ((a&1)<<2))

If the second bit from the right in the pass value is a 1, shift the value 1 bit right, else shift it two bits left.  The macro allows the relative shortcut form instead of typing all of this out every time the function(macro) is needed.

static const int x[] = {
  S1(2),S1(0),S1(1),S1(1),S1(2),S1(3),S1(3),S1(0),
  S1(3),S1(2),S1(2),S1(0),S1(1),S1(1),S1(0),S1(3),
  S1(0),S1(3),S1(3),S1(0),S1(2),S1(2),S1(1),S1(1),
  S1(2),S1(2),S1(0),S1(3),S1(1),S1(1),S1(3),S1(0)
  };

As bad as that is, it's better than:
static const int x[] = {
  (((2&2)>>1) | ((2&1)<<2)),(((0&2)>>1) | ((0&1)<<2)),(((1&2)>>1) | ((1&1)<<2)),(((1&2)>>1) | ((1&1)<<2)),(((2&2)>>1) | ((2&1)<<2)),(((3&2)>>1) | ((3&1)<<2)),(((3&2)>>1) | ((3&1)<<2)),(((0&2)>>1) | ((0&1)<<2)),

By the way, that's for the FIRST line.  :)

Of course, you can always simplify, but that's not self documenting

 
static const int x[] = {
  2<<2, 0, 0, 0, 2<<2, 3<<2, 3<<2, 0
etc....


Good Luck,
Kent
0
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 17834557

Err...  The last example should be:

static const int x[] = {
  2>>1, 0, 1<<2, 1<<2, 2>>1, 3>>1, 3>>1, 0,

Which is:

static const int x[] = {
  1, 0, 4, 4, 1, 1, 1, 0,


Kent
0
 

Author Comment

by:IAJWDDIY
ID: 17834739
Hi Kent,

The static const int x[] bit, is that an array?

Thank you.
0
 
LVL 37

Expert Comment

by:momi_sabag
ID: 17834893
yep
that is an array on int values
the number of elemnts in the array is determined by the number of values in the initiation (32 in your case)
remember that c array are zero based
0
 

Author Comment

by:IAJWDDIY
ID: 17835182
Kent,

Thank you.
0

Featured Post

Technology Partners: 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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

688 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