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. #1
    Registered User
    Join Date
    Jul 2012
    Posts
    36

    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...
    Last edited by tennisstar; 12-03-2012 at 05:28 AM.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,206
    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.
    Right 98% of the time, and don't care about the other 3%.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,433
    Quote 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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,437
    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".
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Jul 2012
    Posts
    36
    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 subscribe to a feed

Similar Threads

  1. Bitwise And
    By Alan Gott in forum C Programming
    Replies: 21
    Last Post: 11-22-2011, 02:09 PM
  2. Bitwise 'and' vs '=='
    By Ducky in forum Windows Programming
    Replies: 4
    Last Post: 07-27-2009, 12:37 PM
  3. 64 Bitwise AND
    By Lostsheep in forum C++ Programming
    Replies: 2
    Last Post: 06-16-2008, 12:17 PM
  4. Bitwise OR
    By tinkerbell20 in forum C++ Programming
    Replies: 4
    Last Post: 06-11-2005, 02:23 AM
  5. bitwise help
    By linuxdude in forum C Programming
    Replies: 8
    Last Post: 11-20-2003, 07:37 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21