public static void Write7BitEncodedInt(this Stream stream, int value) { do { int high = (value >> 7) & 0x01ffffff; byte b = (byte)(value & 0x7f); if (high != 0) { b = (byte)(b | 0x80); } stream.WriteByte(b); value = high; } while (value != 0); }