×
Create a new article
Write your page title here:
We currently have 3,189 articles on s23. Type your article name above or create one of the articles listed here!



    s23
    3,189Articles

    Text2ascii: Difference between revisions

    Content added Content deleted
    imported>mutante
    m (New page: <pre> #!/bin/bash # Convert string to ASCII code # mutante / s23.org declare -a INPUT echo "Enter characters seperated by space to be converted to ASCII code. " read -a INPUT char_count=${...)
     
    imported>mutante
    mNo edit summary
     
    (2 intermediate revisions by the same user not shown)
    Line 4: Line 4:
    # mutante / s23.org
    # mutante / s23.org
    declare -a INPUT
    declare -a INPUT
    echo "Enter characters seperated by space to be converted to ASCII code. "
    echo "Enter characters separated by space to be converted to ASCII code. "
    read -a INPUT
    read -a INPUT
    char_count=${#INPUT[*]}
    char_count=${#INPUT[*]}
    # echo $char_count
    i=0
    i=0
    while [ $i -lt $char_count ]; do
    while [ $i -lt $char_count ]; do
    Line 17: Line 16:
    </pre>
    </pre>


    Example:
    Can you change this so that input does not have to be seperated by spaces anymore?

    <pre>
    mutante@cgn:~$ ./text2ascii.sh
    Enter characters seperated by space to be converted to ASCII code.
    F O O B A R
    F - 70
    O - 79
    O - 79
    B - 66
    A - 65
    R - 82
    </pre>

    Can you change this so that input does '''not''' have to be separated by spaces anymore? So that FOOBAR would produce the same result. Thanks [[User:mutante|mutante]] 22:52, 1 April 2008 (CEST)


    [[Category:ASCII]]
    [[Category:ASCII]]
    [[Category:Scripts]]
    [[Category:Scripts]]
    [[Category:Bash]]

    Latest revision as of 20:52, 1 April 2008

    #!/bin/bash
    # Convert string to ASCII code
    # mutante / s23.org
    declare -a INPUT
    echo "Enter characters separated by space to be converted to ASCII code. "
    read -a INPUT
    char_count=${#INPUT[*]}
    i=0
    while [ $i -lt $char_count ]; do
    ASCII=`perl -e 'print ord shift' ${INPUT[$i]}`
    CHAR=${INPUT[$i]}
    echo -e "$CHAR - $ASCII"
    i=$(($i+1))
    done
    

    Example:

    mutante@cgn:~$ ./text2ascii.sh
    Enter characters seperated by space to be converted to ASCII code.
    F O O B A R
    F - 70
    O - 79
    O - 79
    B - 66
    A - 65
    R - 82
    

    Can you change this so that input does not have to be separated by spaces anymore? So that FOOBAR would produce the same result. Thanks mutante 22:52, 1 April 2008 (CEST)

    Cookies help us deliver our services. By using our services, you agree to our use of cookies.
    Cookies help us deliver our services. By using our services, you agree to our use of cookies.