printing 0x00 in ascii

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joseph Suprenant

    printing 0x00 in ascii

    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


  • Victor Bazarov

    #2
    Re: printing 0x00 in ascii

    "Joseph Suprenant" <laclac01@yahoo .com> wrote...[color=blue]
    > 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[/color]
    view[color=blue]
    > my file my file is messed up just a little bit. Anyone have any ideas?
    > let me know[/color]

    (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


    Comment

    • Ivan Vecerina

      #3
      Re: printing 0x00 in ascii

      "Joseph Suprenant" <laclac01@yahoo .com> wrote in message
      news:vxWub.1266 06$ZC4.82041@tw ister.nyroc.rr. com...
      | 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(charToBeSe nt); 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
      --
      Ivan Vecerina - expert in medical devices, software - info, links, contact information, code snippets



      Comment

      • Noah Roberts

        #4
        Re: printing 0x00 in ascii

        Joseph Suprenant wrote:
        [color=blue]
        > 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[/color]

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

        it is[color=blue]
        > 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[/color]

        Try Base64. There is an RFC.

        NR

        Comment

        Working...