|
-
Oct 11th, 2012, 05:30 PM
#1
Need help on Java meanings
I'm currently trying to convert a Java application into VB6 code and I am not real familiar with Java so I have a few questions and hope someone can help me
The following variables are defined as int in the Java app:
clear
code_mask
datum
Now I come across tthe following and I don't know what they mean
break;
clear = 1 << data_size;
datum += ( ( (int) block[ bi ] ) & 0xff ) << bits;
continue;
datum >>= code_size;
datum = bits = count = first = top = pi = bi = 0;
In the below statement does top++ mean to increment top after or before the action takes place
pixelStack[ top++ ] = suffix[ code ];
Last edited by jmsrickland; Oct 11th, 2012 at 06:14 PM.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Oct 11th, 2012, 10:49 PM
#2
Re: Need help on Java meanings
I haven't done much Java programming but its syntax is C-based so all that stuff is the same in C# or C++ or pretty much any other C-based language.
The 'break' keyword breaks out of the current block. For instance, you might perform a loop and test a condition part way through and end the loop if it's true. VB.NET has equivalent Exit statements, e.g. Exit For, Exit Do, etc. I don't think VB6 has a direct equivalent so your best option would depend on the scenario. You may not have a choice but to use a GoTo.
The << and >> operators are bit-shift operators and they work on the binary form of a number. For instance, 00010100 (20) shifted 2 bits to the left would be 01010000 (80). If you shift all the digits in a decimal number one place to the left, it is equivalent to multiplying by 10. Because binary is base 2, shifting bits one place to the left is equivalent to multiplying by 2. I don;t know whether VB6 has bit-shift operators but you can look it up. If not then you can use multiplication and division instead.
The 'continue' keyword ends the current iteration of a loop and commences the next. VB.NET added an equivalent Continue keyword in its third or fourth generation. Prior to that, the recommendation was to use a GoTo to jump to a label at the very bottom inside the loop. That's what you'd have to do in VB6 too.
Most binary operators can be combined with an = to perform the binary operation using a variable and another value and then assign the result back to the same variable. This:
Code:
datum >>= code_size;
is equivalent to this:
Code:
datum = datum >> code_size;
As you haven't highlighted the += in this line:
Code:
datum += ( ( (int) block[ bi ] ) & 0xff ) << bits;
I assume that you are somewhat familiar with those combined binary assignment operators.
In C-based languages, an assignment actually returns a value, that being the value that assigned. As a result, you are able to chain assignments. This expression:assigns the value zero to the 'bi' variable and returns zero, so that expression can then be assigned to another variable:That means that this code:
Code:
datum = bits = count = first = top = pi = bi = 0;
is equivalent to:
Code:
bi = 0;
pi = bi;
top = pi;
first = top;
count = first;
bits = count;
datum = bits;
Basically that's a quick way to initialise several variables.
The ++ increment and -- decrement operators can be used pre and post. When you see '++var', the operator comes first so the increment comes first, i.e. increment the variable and then use the variable, so the new value gets used. When you see 'var++', the operator comes last so the increment comes last , i.e. use the variable and then increment the variable, so the old value gets used.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|