need help with file compression program

This is a discussion on need help with file compression program within the C++ Programming forums, part of the General Programming Boards category; I want to make a file compression program how can i replace with binary values less than 8 bit??? like ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    82

    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. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,985
    Are you familiar with bit manipulation operations? If not, read up on those.
    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.

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    82
    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. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,985
    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.
    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
    Nov 2011
    Posts
    82
    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. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,985
    That's why I asked if you knew bitwise operations. If you don't understand that, then go read up on them.
    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.

  7. #7
    Registered User
    Join Date
    Nov 2011
    Posts
    82
    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. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,985
    Like I said, use or to set bits.

    For example,
    a |= 0x07
    will set the first 3 bits (since 0x07 == 111 binary).
    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.

  9. #9
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    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.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  10. #10
    Registered User
    Join Date
    Nov 2011
    Posts
    82
    yeah i knw that.. i was just giving an example well thanks for the repply

  11. #11
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    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).
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  12. #12
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Quote Originally Posted by fredsilvester93 View Post
    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.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  13. #13
    Registered User
    Join Date
    Nov 2011
    Posts
    82
    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. #14
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    You don't understand. You cannot make variables smaller.
    Pay more atention to my example, perhaps try and implement that.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  15. #15
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,985
    Quote Originally Posted by oogabooga View Post
    k sry msut nott hav bin mind-reedin goood todaay..
    Speak english. Type out every word fully.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compression/Decompression Wave File and MP3
    By cindy_16051988 in forum Projects and Job Recruitment
    Replies: 51
    Last Post: 04-29-2006, 07:25 AM
  2. Huffman Compression Program
    By ChadJohnson in forum C++ Programming
    Replies: 13
    Last Post: 01-23-2005, 02:49 PM
  3. File Compression
    By Prelude in forum Tech Board
    Replies: 16
    Last Post: 01-01-2005, 06:53 PM
  4. File compression
    By dit6a9 in forum Windows Programming
    Replies: 1
    Last Post: 08-05-2004, 11:44 AM
  5. File Compression
    By Gr3g in forum C++ Programming
    Replies: 1
    Last Post: 04-16-2002, 05:59 PM

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