# Thread: need help with file compression program

1. ## need help with file compression program

I want to make a file compression program
how can i replace with binary values less than 8 bit???

like a == 00001
b == 00010
...

how to work on these bits like adding 3rd bit etc??

plz help me 2. Are you familiar with bit manipulation operations? If not, read up on those. 3. yeah i knw bitwise functions..
i want to say that i want to assign 0001 to a then how can i do that

or u can say i want to replace abc to 001.010.100 and then again replace it with abc

how can i replace a with 001 and futher?? 4. To force some bits to one, use or.
Where the bits you want to be forced to 1 is 1 in the mask.

To force some bits to 0, a typical way is to use
a & ~b
Where the bits you want to force to 0 is 1 in b. 5. i can't get it..i m a beginner.. can you plz explain this or can give me a link to the tutorial plz ??? 6. That's why I asked if you knew bitwise operations. If you don't understand that, then go read up on them. 7. man i have studied the bitwise operator & for AND operation to bit | for OR and ~ for COMPLEMENT..

but i this will still remain 8 bit i want to make a == (some 3 bit) 8. Like I said, use or to set bits.

For example,
a |= 0x07
will set the first 3 bits (since 0x07 == 111 binary). 9. but i this will still remain 8 bit i want to make a == (some 3 bit)
3 bits only have 8 combinations so you can only represent 8 letters. And you seem to be ignoring the 000 combination, which is a waste. Anyway, you'd need at least 5 bits (32 combinations) to represent 26 letters, and that's without distinguishing between upper and lower case.

You can turn 'a' into 000 by simply subtracting 'a' from it. So that part's easy. The problem is to "pack" the bits into bytes, etc. That will require bit-shifting, which are the << and >> operators, plus the | operator.

If you really want to do this right, you might want to look into something called Huffman coding. 10. yeah i knw that.. i was just giving an example well thanks for the repply  11. There are no datatypes less than 8 bits (in modern reality).
To pack things smaller, you need to do things like packing three characters in two bytes.

Lets say you decide to represent A, B, and C as the following series of bits:
A:00000
B:00001
C:00010

To pack these into two bytes, the bits go like this:
00000000 01000100

So then you write out just those two bytes. This is very similar to how 16-bit colour data is stored. There are three colour channels and each is stored in 5 bits (or sometimes 6 for green to use that extra bit). 12. Originally Posted by fredsilvester93 yeah i knw that.. i was just giving an example well thanks for the repply k sry msut nott hav bin mind-reedin goood todaay

Still Huffman coding, and related systems, are interesting for people with functioning brains. 13. size = 2 . which means is storing value 00000000 00000001

and i want it to store 00001 help me plzz!!
Code:
```#include <iostream>

using namespace std;

int main()
{

short int a=0;
a |= 1;
cout  << a << sizeof(a) ;

return 0;
}``` 14. You don't understand. You cannot make variables smaller.
Pay more atention to my example, perhaps try and implement that. 15. Originally Posted by oogabooga k sry msut nott hav bin mind-reedin goood todaay..
Speak english. Type out every word fully. Popular pages Recent additions 