how do you make a string of binary numbers from an array

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

    how do you make a string of binary numbers from an array

    Hi,
    I have an array of numbers, and I need to turn it into a single binary
    string. How do I do that?
    Thanks
    B


  • Carl Vondrick

    #2
    Re: how do you make a string of binary numbers from an array

    Bint wrote:
    I have an array of numbers, and I need to turn it into a single binary
    string. How do I do that?
    Sorry, but what you are trying to do?

    You could do something like this:

    $string = array(1,2,3,5,6 ,7);
    $output = '';
    foreach ($string as $ascii)
    {
    $output .= chr($ascii);
    }

    Comment

    • IchBin

      #3
      Re: how do you make a string of binary numbers from an array

      Carl Vondrick wrote:
      Bint wrote:
      > I have an array of numbers, and I need to turn it into a single
      >binary string. How do I do that?
      >
      Sorry, but what you are trying to do?
      >
      You could do something like this:
      >
      $string = array(1,2,3,5,6 ,7);
      $output = '';
      foreach ($string as $ascii)
      {
      $output .= chr($ascii);
      }
      Is that ascii and not binary?

      Thanks in Advance...
      IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
      _______________ _______________ _______________ _______________ ______________

      'If there is one, Knowledge is the "Fountain of Youth"'
      -William E. Taylor, Regular Guy (1952-)

      Comment

      • Carl Vondrick

        #4
        Re: how do you make a string of binary numbers from an array

        IchBin wrote:
        Is that ascii and not binary?
        What are you trying to convert to and from?

        For example, ascii code --letter.

        Comment

        • Rik

          #5
          Re: how do you make a string of binary numbers from an array

          Bint wrote:
          Hi,
          I have an array of numbers, and I need to turn it into a single
          binary string. How do I do that?
          Thanks
          B
          Concating the items from decimal to binary?

          I'm not really sure how you want to do this, but something like this:

          $array = array(7,12,10,2 ,3);
          function concat_dec2bin( $v,$w){
          $v .= decbin($w);
          return $v;
          }
          $string = array_reduce($a rray,'concat_de c2bin');

          Which will result in 111110010101011 (111 = 7, 1100 = 12,1010 = 10,10 = 2,
          11 = 3);

          Grtz,
          --
          Rik Wasmus


          Comment

          • Peter Fox

            #6
            Re: how do you make a string of binary numbers from an array

            Following on from IchBin's message. . .
            >Carl Vondrick wrote:
            >Bint wrote:
            >> I have an array of numbers, and I need to turn it into a single
            >>binary string. How do I do that?
            >>
            >Sorry, but what you are trying to do?
            >>
            >You could do something like this:
            >>
            >$string = array(1,2,3,5,6 ,7);
            >$output = '';
            >foreach ($string as $ascii)
            >{
            > $output .= chr($ascii);
            >}
            >
            >Is that ascii and not binary?
            >
            The OP wants a binary string - That's a bit like asking for a cheese
            steak.

            Looks like the desperate OP should pay more attention in class and not
            come here for their coursework. Better still - If that's the limit of
            their intellectual engagement with programming they should think of an
            alternative career ... such as say a turnip.
            >Thanks in Advance...
            >IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
            >______________ _______________ _______________ _______________ ___
            >____________
            >
            >'If there is one, Knowledge is the "Fountain of Youth"'
            >-William E. Taylor, Regular Guy (1952-)
            --
            PETER FOX Not the same since the statuette business went bust
            peterfox@eminen t.demon.co.uk.n ot.this.bit.no. html
            2 Tees Close, Witham, Essex.
            Gravity beer in Essex <http://www.eminent.dem on.co.uk>

            Comment

            Working...