public static ObjectId readObjectId(byte[] bytes) {
      // Compute the values in big-endian ...
      int time = ((bytes[0] & 0xff) << 24) + ((bytes[1] & 0xff) << 16) + ((bytes[2] & 0xff) << 8)
               + ((bytes[3] & 0xff) << 0);
      int machine = ((bytes[4] & 0xff) << 16) + ((bytes[5] & 0xff) << 8) + ((bytes[6] & 0xff) << 0);
      int process = ((bytes[7] & 0xff) << 8) + ((bytes[8] & 0xff) << 0);
      int inc = ((bytes[9] & 0xff) << 16) + ((bytes[10] & 0xff) << 8) + ((bytes[11] & 0xff) << 0);
      // Create the value object ...
      return new ObjectId(time, machine, process, inc);
   }
public static ObjectId readObjectId ( byte [ ] bytes ) { int time = ( ( bytes [ 0 ] & 0xff ) << 24 ) + ( ( bytes [ 1 ] & 0xff ) << 16 ) + ( ( bytes [ 2 ] & 0xff ) << 8 ) + ( ( bytes [ 3 ] & 0xff ) << 0 ) ; int machine = ( ( bytes [ 4 ] & 0xff ) << 16 ) + ( ( bytes [ 5 ] & 0xff ) << 8 ) + ( ( bytes [ 6 ] & 0xff ) << 0 ) ; int process = ( ( bytes [ 7 ] & 0xff ) << 8 ) + ( ( bytes [ 8 ] & 0xff ) << 0 ) ; int inc = ( ( bytes [ 9 ] & 0xff ) << 16 ) + ( ( bytes [ 10 ] & 0xff ) << 8 ) + ( ( bytes [ 11 ] & 0xff ) << 0 ) ; return new ObjectId ( time , machine , process , inc ) ; }
The BSON specification (or rather the <a href="http://www.mongodb.org/display/DOCS/Object+IDs">MongoDB
documentation</a>) defines the structure of this data:
<p>
<quote>"A BSON ObjectID is a 12-byte value consisting of a 4-byte timestamp (seconds since epoch), a 3-byte
machine id, a 2-byte process id, and a 3-byte counter. Note that the timestamp and counter fields must be stored
big endian unlike the rest of BSON. This is because they are compared byte-by-byte and we want to ensure a mostly
increasing order."</quote>
</p>

@param bytes
@return the ObjectId