NaN:NaN
NaN:NaN

Scale and position your image


NOTE: please consider becoming a supporter if you would like to choose a shape.
View Profile NextGen
Drop file(s), or click here to upload.

    Male

    Joined on 6/5/07

    Level:
    4
    Exp Points:
    160 / 180
    Exp Rank:
    > 100,000
    Vote Power:
    3.96 votes
    Rank:
    Civilian
    Global Rank:
    > 100,000
    Blams:
    0
    Saves:
    2
    B/P Bonus:
    0%
    Whistle:
    Normal

    Java sucks.

    Posted by NextGen - August 5th, 2007


    Just kidding. But it's really starting to frustrate me. I have to finish learning the rest of the Computer Science 2 AP curriculum by the time school starts, but I'm stuck on bitshifts (which is packet 4 of 14, and I have less than a month to go, WOOT extended summer).

    So, here's the little segment of code that's pissing me off. I checked the answer with ActionScript, so I know the answers aren't wrong (some are, and that stumped me for a bit until I called my teacher =P).

    Written in AS for Flashers:
    x = 9, c, d;
    a = new Array(4);
    a[0] = 0;
    a[1] = 1;
    a[2] = 2;
    a[3] = 3;
    for (c = 0; c < 4; c++) {
    x <<= a[c];
    trace(c + " time and x is " + x);
    d = x | a[c];
    trace(d + " ");
    }

    and written in Java for others:
    int x = 9, c, d;
    int a[] = {0,1,2,3};
    for (c = 0; c < 4; c++) {
    x <<= a[c];
    d = x | a[c];
    System.out.print(d + " ");
    }

    I get the bitwise OR part. The only thing I have trouble with is the third pass of the left shift. I keep getting weird numbers. I know the output (duh), but if someone reading this could step me through the process of the loop in its entirety, that'd be super awesome. Thanks!


    Comments

    Comments ain't a thing here.