how to convert binary to string?

Discussion in 'Perl Misc' started by sonet, Mar 2, 2007.

  1. sonet

    sonet Guest

    ex.
    convert "\x00\x0E" to '\x00\x0E'
    sonet, Mar 2, 2007
    #1
    1. Advertising

  2. sonet wrote:
    > ex.
    > convert "\x00\x0E" to '\x00\x0E'


    So you have a character and you want the ASCII (or whatever encoding) code
    point?
    See "perldoc -f ord"

    Although, that's not what _I_ would call converting binary to string (see
    subject line). That sounds more like you got a number and you want its
    binary representation as a string. For that see "perldoc -f sprintf"

    jue
    Jürgen Exner, Mar 2, 2007
    #2
    1. Advertising

  3. sonet wrote:
    > ex.
    > convert "\x00\x0E" to '\x00\x0E'


    $ perl -le'$_ = "\x00\x0E"; s/(.)/ sprintf q[\x%02X], ord $1 /seg; print'
    \x00\x0E


    John
    --
    Perl isn't a toolbox, but a small machine shop where you can special-order
    certain sorts of tools at low cost and in short order. -- Larry Wall
    John W. Krahn, Mar 2, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matej Barac

    Convert string to binary

    Matej Barac, Jan 31, 2005, in forum: C++
    Replies:
    4
    Views:
    33,167
    David Harmon
    Jan 31, 2005
  2. Achim Domma
    Replies:
    3
    Views:
    604
    Sjoerd Mullender
    Feb 17, 2004
  3. Eric
    Replies:
    3
    Views:
    1,048
    Bengt Richter
    Apr 22, 2004
  4. HNT20
    Replies:
    15
    Views:
    27,546
    blairg23
    Oct 8, 2009
  5. Harlin Seritt
    Replies:
    29
    Views:
    1,151
    Paul Rubin
    Feb 24, 2007
Loading...

Share This Page