Take the 2-minute tour ×

I am trying to pack characters into bits in terms of 0's and 1's. I have looked up many websites about bit-packing but I did not get any of them.

I just want a simple idea about bit-packing, and how to do it?


share|improve this question
Do you want to know how to do it or know how it is done? I suggest you just use DefaltorOutputStream or something like it to compress it. –  Peter Lawrey Apr 25 '13 at 10:27
I want to know how to do it. If you have some useful links that may help, I'd appreciate that!. Cheers –  COLD ICE Apr 25 '13 at 10:29
Define 'packing'. Characters are already sets of bits. Do you mean 'compres'? –  EJP Apr 25 '13 at 23:05

3 Answers 3

up vote 0 down vote accepted

A common compression algorithim which has been around a long time is LZW compression.

It is used by GZIP, PKZIP and JAR to name but a few and is suitable for compressing text. It uses a combination of Huffman encoding, arithmetic coding and a few heuristics to make it more efficient.

simple idea about bit-packing

If you find compression and bit packing in general simple, you are a rare breed. ;)

share|improve this answer

Perhaps it can help you

public String StringtoBinary(String s) {

    char[] cArray=s.toCharArray();

    StringBuilder sb=new StringBuilder();

    for(char c:cArray)
        String cBinaryString=Integer.toBinaryString((int)c);

    return sb.toString();
share|improve this answer
Note: this example has a few problems a) it generates a string much larger b) it cannot be decoded c) it produces text from text. –  Peter Lawrey Apr 25 '13 at 10:36

First of all you should find out what compression algorithm you want to use. I recommend reading Huffman compression algorithm. What language are you using BTW ?

share|improve this answer

Your Answer


