# Bitwise...

This is a discussion on Bitwise... within the C++ Programming forums, part of the General Programming Boards category; hey all, i just finished learning c++ from the beginner C++ tutorial series in cprogramming.com... Now i'm here in the ...

1. ## Bitwise...

hey all,
i just finished learning c++ from the beginner C++ tutorial
series in cprogramming.com...
Now i'm here in the "More advanced topics in C and C++" section. (the first lesson - bitwise operators in c and c++) in that lesson i came across a sentence which i did not understand...
please explain the "(for instance ... bit level)" to me:

Another example comes up when dealing with data compression: what if you wanted to compress a file? In principle, this means taking one representation and turning it into a representation that takes less space. One way of doing this is to use an encoding that takes less than 8 bits to store a byte. (For instance, if you knew that you would only be using the 26 letters of the Roman alphabet and didn't care about capitalization, you'd only need 5 bits to do it.) In order to encode and decode files compressed in this manner, you need to actually extract data at the bit level.
how will the 26 letters take up 5 bits only?
(note: i'm well versed with what a bit, nibble and a byte are...)

one more thing...
since i byte = 8 bits... how can you use an encoding that takes less than 8 bits to store a byte?
(i dont know what an encoding is... so explain that as-well)

so my requests in this post are:
1) kindly explain what does Mr. Alex mean by the (for...bit level) sentence (bracketed part)...
2) kindly explain what does Mr. Alex mean by the "encoding that takes up less than 8 bits to store a byte" part...
3) kindle explain what is encoding...

2. A set of 5 bits can represent up 32 distinct values. If you know the input consists only of (upper or lower case) letters, just map each of the 26 letters to a distinct set of 5 bits. That mapping is an encoding.

3. Originally Posted by tennisstar
how will the 26 letters take up 5 bits only?
The idea here is that given one bit, you can represent something with two possible states. For example, you could represent a hyena (0) or a tiger (1), or you could represent a chair (0) or the ocean (1). Given two bits, you can represent something with 2^2 = 4 possible states (where ^ denotes exponentiation), e.g., you could represent a table (00), a guitar (01), a rabbit (10) and a computer (11). However, if you also want to have a comb as one of the possible options (i.e., a total of five possibilities), two bits won't do. You need at least three bits, since 2^3=8, and 8 >= 5.

Hence, with 26 possible letters, you need at least 5 bits, since 2^5=32, and 32 >= 26.

4. The idea here is kind of if we know that our data will only have, say, 26 distinct values (lower case letters), then we don't need 8 bits to store that data. In fact, we only need 5 bits to do that, so why use 8 bits? So we can encode our 8 bit data to 5 bit data.
Another interesting way of doing encoding is huffman's encoding, which just takes the most popular occurring sequence of bytes (ie, data) and says that shall be represented by the bit sequence 1. Then the next popular one might be 01, and so on. A simplified example, but maybe it might give you some intuition. It simply "interprets" data differently by redefining something to mean something else, just as you could say "banana" when you really mean "apple".

5. Thank-you all of you guys...
it helped a lot and i'm really clear of the bit and byte concept...

i feel really happy...
THANK-YOU!!

Popular pages Recent additions