encoding is 33,243 bits long: 11 1111 1000000111000100 (22 bits), followed by 33,220 bits of the value, and a trailing 0. Under Elias delta coding, the same number is 33,250 bits long: 000000000000000 1000000111000100 (31 bits) followed by 33,219 bits of the value. The omega and delta coding are, respectively, 0.07% and 0.09% longer than the ordinary 33,220-bit binary representation of the number. For the encoding of a positive integer , the number of bits needed, , is computable recursively: Example code Encoding void eliasOmegaEncode(char* source, char* dest) { IntReader intreader(source); BitWriter bitwriter(dest); while (intreader.hasLeft()) { int num = intreader.getInt(); BitStack bits; while (num > 1) { int len = 0; for (int temp = num; temp > 0; temp >>= 1) // calculate 1+floor(log2(num)) len++; for (int i = 0; i < len; i++) bits.pushBit((num >> i) & 1); num = len - 1; } while (bits.length() > 0) bitwriter.putBit(bits.popBit()); bitwriter.putBit(false); // write one zero } bitwriter.close(); intreader.close(); } Decoding void eliasOmegaDecode(char* source, char* dest) { BitReader bitreader(source); IntWriter intwriter(dest); while (bitreader.hasLeft()) { int num = 1; while (bitreader.inputBit()) // potentially dangerous with malformed files. { int len = num; num = 1; for (int i = 0; i < len; ++i) { num <<= 1; if (bitreader.inputBit()) num |= 1; } } intwriter.putInt(num); // write out the value } bitreader.close(); intwriter.close(); } Generalizations Elias omega coding does not encode zero or negative integers. One way to encode all non-negative integers is to add 1 before encoding and then subtract 1 after decoding. One way to encode all integers is to set up a bijection, mapping all integers (0, 1, -1, 2, -2, 3, -3, ...) to strictly positive integers (1, 2, 3, 4, 5, 6, 7, ...) before encoding. See also Elias delta (δ) coding Elias gamma (γ) coding Even-Rodeh coding References Further reading External links Implementation in Python Numeral systems Lossless compression algorithms