Re: writing binary data

From: Bill Thompson (bill.thompson_at_GOODYEAR.COM)
Date: 03/29/04

  • Next message: terry.german_at_PHONES4U.CO.UK: "AIX 5.2L "who" question"
    Date:         Mon, 29 Mar 2004 06:41:25 -0500
    To: aix-l@Princeton.EDU
    
    

    Holger,

    I created the following script (called it "hex1"):

    - - - - - snip - - - - -
    #!/bin/sh

        STRING="80DF000038600002540807FE38A00000"

        P1=1; P2=2

        HEX=$(echo $STRING | cut -c${P1}-${P2})

        while [[ -n $HEX ]]; do

            OCT=$(echo "ibase=16\nobase=8\n$HEX" | bc)

            echo "\0${OCT}\c"

            P1=$((P1+2)); P2=$((P2+2))

            HEX=$(echo $STRING | cut -c${P1}-${P2})

        done
    - - - - - snip - - - - -

    And ran it as follows:

    ->sh hex1 >out1

    Now when I run od on the output:

    -> od -x out1
    0000000 80df 0000 3860 0002 5408 07fe 38a0 0000
    0000020

    Bill Thompson
    Sr UNIX Systems Administrator
    The Goodyear Tire & Rubber Co.

    Contains Confidential and/or Proprietary Information
    May Not Be Copied or Disseminated Without Express Consent of The Goodyear Tire & Rubber Company.

    AIX-L Archives: http://marc.theaimsgroup.com/?l=aix-l&r=1&w=2

    ----- Original Message -----
    From: "Jean-Marc Monnez" <monnez.jean-marc@AGORA.MSA.FR>
    Newsgroups: bit.listserv.aix-l
    To: <aix-l@Princeton.EDU>
    Sent: Monday, March 29, 2004 4:52 AM
    Subject: Re: writing binary data

    The escape you need in echo or print is \0 followed by the octal value
    of the byte.
    F.e. to add 80 (hex), use 200 (octal).
    echo "\0200\c" > binfile

    Your main work is octal conversion for each byte....

    Regards

    -- JMM

    -----------------------------
    Jean-Marc MONNEZ
    MSA / AGORA / ATD
    monnez.jean-marc@agora.msa.fr
    -----------------------------

    Holger.VanKoll@SWISSCOM.COM a écrit :

    > Hello Aix-lers,
    >
    > I have this string
    >
    > 80DF000038600002540807FE38A00000
    >
    > containing 16 bytes ( 80 , DF , 00, 00 and so on).
    >
    > I want to have a binary file containg those bytes.
    > So that
    > cat file|od -x
    > would give this output:
    >
    > 0000000 80DF 0000 3860 0002 5408 07FE 38A0 0000
    >
    > I could use cut to get every single byte; f.e.
    >
    > echo 80DF000038600002540807FE38A00000|cut -c1-2
    > echo 80DF000038600002540807FE38A00000|cut -c3-4
    >
    > and I also know how to convert those bytes to decimal, if necessary.
    >
    > I just see no way to write binary data.
    > If $a contains 80 (hex) or 128 (decimal), a echo $a >filename just
    > creates a textfile with 128.
    >
    > Any suggestions?
    >
    > Regards,
    >
    > Holger


  • Next message: terry.german_at_PHONES4U.CO.UK: "AIX 5.2L "who" question"

    Relevant Pages

    • Re: PHP retrieve image from Mysql database
      ... because its a binary data you can just echo the content data. ...
      (comp.lang.php)
    • Re: Problems with mp3
      ... Hmmm... ... Can you give me the binary data for mp3? ... "Echo S" wrote: ...
      (microsoft.public.powerpoint)
    • Re: Problems with mp3
      ... Sonia Coleman ... Microsoft PowerPoint MVP Team ... Can you give me the binary data for mp3? ... >> Echo ...
      (microsoft.public.powerpoint)
    • Re: file download?
      ... Bint wrote: ... That's how I get binary data into my script. ... Echo will return anything you tell it. ...
      (comp.lang.php)
    • How to make an in memory input/output stream?
      ... I am trying to write some binary data. ... Now I want to have an easy way to test the data I wrote to the stream. ... Regards, ... Prev by Date: ...
      (comp.lang.lisp)