printing 0x00 in ascii

J

Joseph Suprenant

Quick question hope someone can help.
I am sending a file accross a radio, i am limited to using only chars. I
get all the data on the receiving end but everytime it gets a 0x00 it is
treated as a 0x20 (ascii whitespace). SO when i go to print it out and view
my file my file is messed up just a little bit. Anyone have any ideas?
let me know
joe
 
V

Victor Bazarov

Joseph Suprenant said:
Quick question hope someone can help.
I am sending a file accross a radio, i am limited to using only chars. I
get all the data on the receiving end but everytime it gets a 0x00 it is
treated as a 0x20 (ascii whitespace). SO when i go to print it out and view
my file my file is messed up just a little bit. Anyone have any ideas?
let me know

(a) What character is _printed_ when a certain char value is
spooled down the output stream is implementation- and platform-
defined. The language cannot dictate that.

(b) What do you expect your program should do? Why do you say
"it is treated as a 0x20"? Treated by whom or by what? What
is that mysterious "it" that "gets a 0x00"?

Victor
 
I

Ivan Vecerina

| Quick question hope someone can help.
| I am sending a file accross a radio, i am limited to using only chars. I
| get all the data on the receiving end but everytime it gets a 0x00 it is
| treated as a 0x20 (ascii whitespace). SO when i go to print it out and
view
| my file my file is messed up just a little bit. Anyone have any ideas?

Maybe your transmission system does not support sending a 0x00,
so some code automatically replaces it with a 0x20.
What you could do is to somehow encode your data to avoid occurrences
of 0x00, or use a filter to generate escaped character sequences.
For example, using '/' as an escape character:

on the sending end:
switch( charToBeSent ) {
case 0x00: send('/'); send('z'); break;
// ... more escaped chars ...
case '/' : send('/'); send('/'); break;
default: send(charToBeSent); break;
}

on the receiving end:
char received = read();
if( received =='/' ) {
received = read(); // get next character
switch( received ) {
case 'z' : received = 0x00;
// ... more escaped chars ...
case '/' : /* -> ok: same char */
default: break;
}
}


hth-Ivan
 
N

Noah Roberts

Joseph said:
Quick question hope someone can help.
I am sending a file accross a radio, i am limited to using only chars. I
get all the data on the receiving end but everytime it gets a 0x00

I am assuming you are sending binary data because 0x00 would not appear
in a text stream.

it is
treated as a 0x20 (ascii whitespace). SO when i go to print it out and view
my file my file is messed up just a little bit. Anyone have any ideas?
let me know

Try Base64. There is an RFC.

NR
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top