This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Java in General and the fly likes Bitwise Operators and Date Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Bitwise Operators and Date Help" Watch "Bitwise Operators and Date Help" New topic
Author

Bitwise Operators and Date Help

J Kneeland
Ranch Hand

Joined: Aug 15, 2004
Posts: 31
I found some code used as an example of how to get the time since 1900 and unsinged 32 bit number for implenting a time server.



Well it doesn't seem to work and this is the first time I have used bit wise operators before. Anyone spot the problem?
Sheldon Fernandes
Ranch Hand

Joined: Aug 18, 2004
Posts: 157
The bitwise operations are being performed correctly. You are probably expecting unsigned values in your time[], but 'byte' is a signed integer. The bytes that have a '1' in the MSB are treated as negative numbers.

You could store the bytes in a short[] or int[].

Sheldon Fernandes
J Kneeland
Ranch Hand

Joined: Aug 15, 2004
Posts: 31
The only problem with this is it has to go into a ByteBuffer. I guess I could store it into a ShortBuffer though.

Edit: Yeah, I need a ByteBuffer so I need an array of bytes.

Thanks
[ September 25, 2004: Message edited by: J Kneeland ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Bitwise Operators and Date Help