Bit Map Compression of Binary Files

Bit Map

A bit map compression scheme consists of a bit map and a physical database which stores the non-constant values. The bit map is employed to indicate the presence or absence of non-constant data. The following example shows how the bit map compression scheme can be employed to implement a version of constant suppression.


Original data string
d1, c, c, d2, c, c, c, d3

Compressed data string
Bit map: 10010001.
Physical database: dl, d2, d3.

For the bit map compression method, the mapping mechanism must search the whole bit map for both forward and backward mapping. And thus, the access time for both forward and backward mapping is O(N), where N is the number of bits in the bit map or equivalently the number of elements in the database.

Program in CPP:
From the above theory, we have designed the program that is stated below. this program takes input from the secondary memory as binary (.bin) file.
thank you!

This program is developed by Md.Mushfiqur Rahman and Abdullah Al Mahmud during the time of undergrad thesis in CSE, KUET.

/*This program is developed by Md.Mushfiqur Rahman and 
Abdullah Al Mahmud during the time of undergrad thesis. 
CSE,KUET. 7 Apr,2010 */

#include <iostream.h>
#include <fstream.h>

#define size 8000 //number of inputs to be taken from a file named rawdata.bin
#define size2 3000

	int logd[size],phyd[size2],bits[size];
	int length,newl;
	int cnst = 0;

	int readfile(int init[],int &amp;len)
		ifstream in("rawdata.bin");
			cout<<"can NOT open file"<<endl;
			return 0;
		for(int i=0; i&gt;init[i]; (reinterpret_cast( &amp; init[i] ),sizeof( init[i] ));
		cout<<"Data has received from the file rawdata.bin"<<;endl;
		return 0;

	void print(int a[],int n)
		for(int i=0;i&lt;n;i++)
			cout>>a[i]<<' ';

	void writefile(int a[],int n,ofstream of)
		for(int i=0;i<n;i++)
			of.write(reinterpret_cast( &amp; a[i] ),sizeof( a[i] ));
		//of<<a[i]<<' ';


	void newfile()

		ofstream out1("bitmap.bin");

		ofstream out2("physicaldatabase.bin");


void main()


	cout<<"The original data(Logical database) is :";

	int j=0;
	for(int i=0; i<length ;i++)


	cout<<"\nThe bitmap is :";

	cout<<"\nThe compressed data is :";


3 thoughts on “Bit Map Compression of Binary Files

  1. Hi, thanks for your comment in my blog. I am really looking forward to seeing you in my forum and also your post about the forum. 🙂 I really appreciate it.

    I see that you are from CSE. Did you take part in the programing contest held in SUST a few days ago?

    best wishes…

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s