Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem displaying char with ASCII code 255

Status
Not open for further replies.

paskuda

Programmer
Jan 27, 2005
104
PL
I'm having that probably very stupid problem, yet I can't find an answer, so ...
My application has to make a hex dump of some buffer (read from binary file). I have a pointer to that buffer:
Code:
char *headerPtr;
To read it byte by byte I wrote a function
Code:
char header::getByteAtPos(int pos){
if( pos > hsize ) {
  return NULL;
  }
char ret = *(headerPtr + pos);
return ret;
}
As you see, first I check whether position is not outside the buffer, then I increment buffer pointer and read the char located at calculated position.

In the main() function I have following piece of code :
Code:
for(int i=0,w=0; i<X->size; i++, w++) {
  [cut unimportant formatting stuff]
  sp = X->getByteAtPos(i);
  printf("%02X ",sp);
 }
Everything works fine and dumped values are correct (I compared them with Hexplorer output unless returned char's ASCII code is 255. See the output yourself:
Code:
4D 5A 50 00 02 00 00    00 04 00 0F 00 FFFFFFFF FFFFFFFF 00

These FFFFFFFF fields should be displayed as FF. Everything else is correct. At first, I thought I'm doing something wrong with printf(), but using cout << hex << int(sp) produced the same.

Any ideas ?

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top