Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Sep 2006

    Writing bit by bit onto a file

    Hii Folks,

    I am working on Huffman Encoding for compression.In order to reduce the size of files(effectively compress them) I need to replace each character by their coreesponding huffman code.So its highly likely that an 8 bit character by 2-3 bits.

    I was wondering if anybody of you could help in writing bit by bit on a file.


  2. #2
    Super Contributor
    Join Date
    Mar 2003

    Re: Writing bit by bit onto a file

    Don't write bit-by-bit to a file, but fill a memory buffer bit-by-bit and once you have enough bits to fill at least a byte (or whatever size chunk makes sense; 256 bytes, 512 bytes, 1024 bytes, whatever), write the byte(s) to a file.

    Of course, the last/final bits, if it is not an even byte, by chance, needs to be padded to full 8 bits. And you, of course need to know (store) what's such padding so that you don't mistakenly handle such padding as actual data/content that you need to process.

Similar Threads

  1. File corrupted - with signed sis
    By annehj in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 4
    Last Post: 2007-12-10, 13:44
  2. File reading & writing help, wav file redaing help
    By shubhamlahoti in forum Mobile Java General
    Replies: 6
    Last Post: 2007-06-27, 09:07
  3. Replies: 3
    Last Post: 2006-05-02, 20:12
  4. could not find thread.mbg and thread.rsg
    By deercrane in forum Symbian
    Replies: 3
    Last Post: 2006-04-18, 09:44

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts