A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Binary to text

  1. #1
    Illuminatus! fospher.com's Avatar
    Join Date
    Jan 2002
    Location
    5th Dimension
    Posts
    2,185

    Binary to text

    I used to know this a year ago, but know its totally out of my head and bugging me.

    How do I convert text to binary? Do I have to convert it to ascii first, and if I do, I remember there was a shortcut for text to ascii conversion, but thats all gone now, flushed out of my brain with alcohol.

    I need your brains...

  2. #2
    poet and narcisist argonauta's Avatar
    Join Date
    Nov 2001
    Location
    Under the bed
    Posts
    2,080
    my blog: blog.innocuo
    Sponsored by your mom.

  3. #3
    Always Twirling Toward Freedom pooon's Avatar
    Join Date
    Oct 2001
    Location
    On the sunny beaches of Canada
    Posts
    896
    This is the one I always used to use

    http://nickciske.com/tools/binary.php

  4. #4
    poet and narcisist argonauta's Avatar
    Join Date
    Nov 2001
    Location
    Under the bed
    Posts
    2,080
    Originally posted by pooon
    This is the one I always used to use

    http://nickciske.com/tools/binary.php
    mine is in flash...buuuuuuuuuuuuuh to you
    my blog: blog.innocuo
    Sponsored by your mom.

  5. #5
    Illuminatus! fospher.com's Avatar
    Join Date
    Jan 2002
    Location
    5th Dimension
    Posts
    2,185
    Right, there's many convertors out there, I was looking for a manual way. Im looking through your source right now argo in the strtobit function, but frankly not understanding it. Sorry, I guess I turned into a thick designer...

  6. #6
    poet and narcisist argonauta's Avatar
    Join Date
    Nov 2001
    Location
    Under the bed
    Posts
    2,080
    Originally posted by fospher.com
    Right, there's many convertors out there, I was looking for a manual way. Im looking through your source right now argo in the strtobit function, but frankly not understanding it. Sorry, I guess I turned into a thick designer...
    actually flash does all the work for you:

    code:

    function strToBin(lqlstr) {
    //create and array, each element in the array is a character of the string,
    //so if you right "apple" the array is "a,p,p,l,e"
    var charArray = lqlstr.split("");
    var i = 0;
    //i go through each element in the array and call the chartobin function for each element (that means i call the function for each letter
    while (i<charArray.length) {
    charArray[i] = (charToBin(charArray[i]));
    i++;
    }
    return charArray.join("");
    }


    //take a character as a parameter
    function charToBin(lqlchar) {
    //get the character code (which is a number) of the letter
    var code = lqlchar.charCodeAt(0);
    //here, convert the code (number) to a number with base 2 (binary) and still, use it as a string
    //then add 4 0000, just in case, to the beginning of the string (cause the minimum number it will return, is a 4 digit number (but i need 8 digits, for it to be a byte, i believe)
    //so, you ll have something like "00001111"
    //or "000012345678"
    var bincode = "0000"+code.toString(2);
    //here, i just make sure that the return code has 8 digits
    //so if it is "00001234567" it will be cut to "01234567"
    bincode = bincode.substr(-8, 8);
    return bincode;
    }




    im not really good at explaining stuff
    my blog: blog.innocuo
    Sponsored by your mom.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center