long readLongLittleEndian( ) { // 8 bytes, get each byte unsigned, and accumulate them onto the long long accum = 0; for ( int shiftBy=0; shiftBy<64; shiftBy+=8 ) { // must cast to long or the shift would be done modulo 32 accum |= (long)( readByte() & 0xff ) << shiftBy; } return accum; // rem in JDK 1.5+ you can say: // return Long.reverseBytes( l ); }