39 #ifndef T_COMPARE_BITS
40 #define T_COMPARE_BITS
61 int compareBytsWithFile(
const char * szFileName,
const char * pcByts,
62 const unsigned int uiNumberOfByts ){
66 cout<<endl<<
"Comparing the given byts with the byts in the file: "<<endl;
69 unsigned int uiBytsLoaded = 0;
70 ifstream * file =
new ifstream( szFileName , ios_base::in | ios_base::binary );
72 if ( (file == NULL) || ( ! file->is_open()) ){
73 cerr<<
"Error: Could not open the file "<< szFileName <<
" . "<<endl;
78 char pcLoadedByts[ uiNumberOfByts + 8 ];
80 while ( ! file->eof() && ! file->fail() && ( uiBytsLoaded < (uiNumberOfByts + 8) ) ){
82 file->get( pcLoadedByts[ uiBytsLoaded ] );
87 cerr<<
"Error: Still more data to load, but "<< uiBytsLoaded <<
88 " byts loaded when yust "<< uiNumberOfByts <<
89 " byts to compare with . "<<endl;
95 cerr<<
"Error: Error while loading data. "<<endl;
100 if ( uiBytsLoaded != uiNumberOfByts ){
101 cerr<<
"Error: Number of byts not equal, "<< uiBytsLoaded <<
102 " byts loaded when yust "<< uiNumberOfByts <<
103 " byts to compare with . "<<endl;
109 unsigned short usLineLenght = 32;
110 for (
unsigned int uiActualPosition = 0;
111 ( uiActualPosition < uiNumberOfByts ) ||
112 ( uiActualPosition < uiBytsLoaded );
113 uiActualPosition += usLineLenght ){
116 for (
unsigned short usLinePosition = 0;
117 usLinePosition < usLineLenght; usLinePosition++ ){
119 if ( (uiActualPosition + usLinePosition) < uiNumberOfByts ){
120 cout<<
"0x"<<setfill(
'0')<<setw(2)<<
121 (
unsigned short)((
unsigned char)pcByts[ uiActualPosition + usLinePosition ]) <<
";";
127 cout<<endl<<
"File : ";
128 for (
unsigned short usLinePosition = 0;
129 usLinePosition < usLineLenght; usLinePosition++ ){
131 if ( (uiActualPosition + usLinePosition) < uiBytsLoaded ){
132 cout<<
"0x"<<setfill(
'0')<<setw(2)<<
133 (
unsigned short)((
unsigned char)pcLoadedByts[ uiActualPosition + usLinePosition ]) <<
";";
143 for (
unsigned int uiActualPosition = 0;
144 ( uiActualPosition < uiNumberOfByts ) ||
145 ( uiActualPosition < uiBytsLoaded );
146 uiActualPosition++ ){
148 if ( ( uiActualPosition < uiNumberOfByts ) && ( uiBytsLoaded <= uiActualPosition ) ){
150 cerr<<
"Error: The "<< uiActualPosition <<
" byte could not be loaded. "<<endl;
153 }
else if ( ( uiNumberOfByts <= uiActualPosition ) && ( uiActualPosition < uiBytsLoaded ) ){
154 cerr<<
"Error: The "<< uiActualPosition <<
" byte could be loaded, but isn't ther to compare. "<<endl;
158 if ( pcByts[ uiActualPosition ] != pcLoadedByts[ uiActualPosition ] ){
159 cerr<<
"Error: The "<< uiActualPosition <<
"'th byte in the file is "<<
160 hex <<
"0x"<<setfill(
'0')<<setw(2)<<
161 (
unsigned short)((
unsigned char)pcLoadedByts[ uiActualPosition ]) <<
" but should be "<<
162 "0x"<<setfill(
'0')<<setw(2)<<
163 (
unsigned short)((
unsigned char)pcByts[ uiActualPosition ]) <<
" "<<dec<<endl;