code: public static void writeInt(int num, ByteBuffer buf) {
          if(num == 0) {
              buf.put((byte)0);
              return;
          }
          final byte bytes_needed=bytesRequiredFor(num);
          buf.put(bytes_needed);
          for(int i=0; i < bytes_needed; i++)
              buf.put(getByteAt(num, i));
      }
docs: Writes an int to a ByteBuffer
  @param num the int to be written
  @param buf the buffer