aspose file tools*
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 Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Bitwise Operators and Date Help" Watch "Bitwise Operators and Date Help" New topic

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.

[ September 25, 2004: Message edited by: J Kneeland ]
I agree. Here's the link:
subject: Bitwise Operators and Date Help
Similar Threads
Need Help Converting a long to a Byte Array
Shift Operator
SIGNED Left Shift operator???
How to use Bitwiae operators?
Expressing unsigned integers and longs