NextGen

Reviews Favorites Flash News Main
NextGen

Age/Gender: n/a, Male

Newgrounds Stats

Sign-Up Date:
6/5/07

Level: 4
Aura: Neutral

Rank: Civilian
Blams: 0
Saves: 2
Rank #: 222,443

Whistle Status: Normal

Exp. Points: 160 / 180
Exp. Rank #: 181,131
Voting Pow.: 3.96 votes

BBS Posts: 7 (0.01 per day)
Flash Reviews: 8
Music Reviews: 0
Trophies: 0
Stickers: 0

Latest News

NextGen

Java sucks.

Posted by NextGen Aug. 5, 2007 @ 1:36 AM EDT

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!

0 comments | Log in to comment! | Share this!