Win a copy of GANs in ActionE this week in the AI forum
or WebAssembly in Action in the JavaScript forum!

Gary Busby

+ Follow
since Feb 02, 2003
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Gary Busby

I have been doing some exercises in Mugal and Rasmussen's book. The exercise asks to "Create a method that takes an int as an argument and returns a String objectrepresenting the binary representation of the integer. Given the argument 42, it should return "101010"."
I had a go but came no-where close. The answer in the back of the book has me speechless. I had placed some System.out.println's to see how the program works and then reffered to the book to work it out but I can't see how it works.
Could someone explain how this program works between the From here to Here markers?
public class scjpex_32 {
public static void main(String args[]) {

public static String toBinary(int i) {
String binary = "";
do {
// From here
int lowBit = (i&1);
String newDigit = ((lowBit == 0) ? "0" : "1");
binary = newDigit + binary;
// To here
i>>>= 1;
} while (i !=0);
return binary;
[ October 09, 2003: Message edited by: Gary Busby ]
[ October 09, 2003: Message edited by: Gary Busby ]
[ October 09, 2003: Message edited by: Gary Busby ]
I was trying to get it straight by explaining it.
Your reply is great.
Thank you,
I am working towards the SCJP 1.4 and have been working through the Mughal and Rasmussen Cert Guide. I see I have alot more work to do on bit wise operators etc.
To the point though. I have been trying to figure out how a sequence of bits could be negative or positive when it could easily be a whole number.
By trawling various threads I see that if the first bit is 0 or 1 in the highest position for that primitive type signifies whether the decimal representation is negative or positive.
eg> the dots signify zeros or ones
on a primative
byte 0... .... means it is positive and 1... .... is negative
short 0... .... .... .... is positive and 1... .... .... .... negative
int 0(31dots) is positive and 1(31dots) is negative
byte has one sign and 7 positions
short has one sign and 15 positions
I just need to get this straight in my head before moving on.
Sorry if this is obvious.
Thanks so much for your help so far, and the help in the future.
Thank you to all who helped.
Best regards,
16 years ago
I am looking to protect the session by creating a backup session. Then if the app has been inactive for the standard 30mins then a check could be made to see if the session still exists. If it does not exist, an option is given to restore the session from the backupSession.
All I need to know is if the main session (Call it 'sess') times-out at 30mins and backupsSession is set to:
backupSession.setMaxInactiveInterval(60*60*60*4); // Set to 4 hours
When the timeout occurs will backupSession still exist or is backupSession riding on the back of sess and will timeout at the 30minute mark?
Thank you in advance,
16 years ago