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
Printable View
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
Are you familiar with bit manipulation operations? If not, read up on those.
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??
To force some bits to one, use or.
a | mask
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.
i can't get it..i m a beginner.. :( can you plz explain this or can give me a link to the tutorial plz ???
That's why I asked if you knew bitwise operations. If you don't understand that, then go read up on them.
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)
Like I said, use or to set bits.
For example,
a |= 0x07
will set the first 3 bits (since 0x07 == 111 binary).
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.Quote:
but i this will still remain 8 bit i want to make a == (some 3 bit)
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.
yeah i knw that.. i was just giving an example :) well thanks for the repply :)
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).
k sry msut nott hav bin mind-reedin goood todaay
Still Huffman coding, and related systems, are interesting for people with functioning brains.
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;
}
You don't understand. You cannot make variables smaller.
Pay more atention to my example, perhaps try and implement that.