Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Bitwise Operators and Date Help

 
J Kneeland
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic