الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

كود البحث داخل ملف Binary

بدأه apro في 5 يناير 2009 · 0 رد · 306 مشاهدة · في ارشيف قسم C/C++
مشاركة: واتساب X فيسبوك تيليجرام
#1

السلام عليكــم ورحمـة الله وبركاتــه

const int size = sizeof(long);
union my {  
	char arr[size];  
	ong buff;
};
char pattern = 21; // binary pattern 10101
int pattern_length = 5;
int match_pattern = 31; // binary 11111
my cache;
ifstream file ("my.bin", ios::in|ios::binary|ios::ate);
if (file.is_open())
{  
  size = file.tellg();   
file.seekg (0, ios::beg);	
file.read (&cache.arr[0] + 1, size-1); // the first byte always will be filled with last part from the cache	
file.close();
}// ..... make necessary search here
for (int i = size*8 - pattern_length; i>=0; --i)
{	if ((cache.buff >> i) ^ pattern = 31) 
 // .... you have found the pattern in   (8*size   - (5 + i)) -th bit from left
}
// ... move  the last bits to the beginning
cache.arr[0] = (cache.arr[size-1] | 0) << 3; // writing the last 5 bits in the beginning of first byte of cache// .. now you can read from stream in same way as above

اذا عجبكم ادعولي

تم تعديل هذه المشاركة بواسطة apro في 5 يناير 2009 في 00:53

مواضيع مشابهة