Results 1 to 4 of 4

Thread: Convert Java To VB

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Convert Java To VB

    I'm in the process of converting some old Java code to VB and I run into a few problems now and then

    Here is one of them

    Java code

    Code:
    do {
       int k1 = ai[j1];
       int l1 = (k1 & 0xff0000) >> 16;
       int i2 = (k1 & 0xff00) >> 8;
       int j2 = k1 & 0xff;
       l1 = Math.min(255, (l1 * c) / 100);
       i2 = Math.min(255, (i2 * c) / 100);
       j2 = Math.min(255, (j2 * c) / 100);
       ai[j1] = (k1 & 0xff000000) + (l1 << 16) + (i2 << 8) + j2;
    } while(++j1 < 483);
    The lines in bold red are what I am having trouble with as I do not know how to convert them to VB code


    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.

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Convert Java To VB

    The & is an And operation. The >> and << are bitshift operations.

    I'd replace the adds (+) with Or which is much more proper here.

  3. #3
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Convert Java To VB

    Code:
    Private Enum PowersOfTwo
        [2 ^ 8] = 2 ^ 8
        [2 ^ 16] = 2 ^ 16
    End Enum
    
    l1 = (k1 And &HFF0000) \ [2 ^ 16]
    i2 = (k1 And &HFF00) \ [2 ^ 8]
    . . .
    ai(j1) = (k1 And &HFF000000) Or (l1 * [2 ^ 16]) Or (i2 * [2 ^ 8]) Or j2
    Since exponentiation is an expensive operation, I've defined constants for them.

    Also, make sure that the left-shift operations don't shift the most-significant bit of the base to the sign-bit position, or else the result will be incorrect. For example, the maximum number that the l1 variable in the equation (l1 * [2 ^ 16]) can hold is 32,767 (&H7FFF).
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  4. #4
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,854

    Re: Convert Java To VB

    On vbSpeed: ShiftRight and LeftShift

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width