Ascii to Bin
Um normalen Text mitteln PHP in Binär zu verwandeln, braucht es keine große Funktion, welche alle Zeichen des Textes ersetzt, so was kann PHP fast allein.
1 2 3 4 5 6 7 8 9 10 11 | // ascii to bin function ascii_to_bin ($var_sAsciiIn = '') { $var_sAsciiIn = utf8_decode($var_sAsciiIn); $var_sBinOut = ''; for ($count_i = 0; $count_i < strlen($var_sAsciiIn); $count_i++) { $var_sBinOut .= sprintf('%08b', ord($var_sAsciiIn{$count_i})) . ' '; } return $var_sBinOut; } |
Bin to Ascii
Natürlich klappt das auch in die andere Richtung, ebenfalls ohne großen Aufwand.
1 2 3 4 5 6 7 8 9 10 11 | // bin to ascii function bin_to_ascii($var_sBinIn = '') { $var_sAsciiOut = ''; $var_sBinIn = str_replace(' ', '', $var_sBinIn); for ($count_i = 0; $count_i < strlen($var_sBinIn); $count_i += 8) { $var_sAsciiOut .= chr(bindec(substr($var_sBinIn, $count_i, 8))); } return $var_sAsciiOut; } |
Anwendung
Das Ganze ist natürlich recht schnell in eine entsprechende Seite eingebaut.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
Fazit
Bleibt mir nur noch zu sagen …
01000101 01110011 00100000 01100111 01101001 01100010 01110100 00100000 01101110 01110101 01110010 00100000 00110001 00110000 00100000 01000001 01110010 01110100 01100101 01101110 00100000 01110110 01101111 01101110 00100000 01001101 01100101 01101110 01110011 01100011 01101000 01100101 01101110 00101110 00100000 01000100 01101001 01100101 00101100 00100000 01100100 01101001 01100101 00100000 01100010 01101001 01101110 11100100 01110010 00100000 01110110 01100101 01110010 01110011 01110100 01100101 01101000 01100101 01101110 00101100 00100000 01110101 01101110 01100100 00100000 01100100 01101001 01100101 00101100 00100000 01100100 01101001 01100101 00100000 01100101 01110011 00100000 01101110 01101001 01100011 01101000 01110100 00100000 01110110 01100101 01110010 01110011 01110100 01100101 01101000 01100101 01101110 00101110
:-)

01010011 01100101 01101000 01110010 00100000 01110011 01100011 01101000 01101111 01100101 01101110 01100101 00100000 01010011 01100001 01100011 01101000 01100101 00101100 00100000 01101101 01101001 01110010 00100000 01100110 01100101 01101000 01101100 01110100 00100000 01111010 01110111 01100001 01110010 00100000 01100111 01100101 01110010 01100001 01100100 01100101 00100000 01100101 01101001 01101110 01100101 00100000 01001101 01101111 01100101 01100111 01101100 01101001 01100011 01101000 01101011 01100101 01101001 01110100 00100000 01100100 01100001 01110011 00100000 01101000 01101001 01100101 01110010 00100000 01110101 01101101 01111010 01110101 01110011 01100101 01110100 01111010 01100101 01101110 00100000 00101101 00100000 01100001 01110101 01110011 01110011 01100101 01110010 00100000 01101001 01101110 00100000 01100100 01101001 01100101 01110011 01100101 01101101 00100000 01001011 01101111 01101101 01101101 01100101 01101110 01110100 01100001 01110010 00100000 01101110 01100001 01110100 01110101 01100101 01110010 01101100 01101001 01100011 01101000 00101110 00100000 01000100 01100101 01101110 00100000 01000111 01100101 01100101 01101011 01100110 01100001 01101011 01110100 01101111 01110010 00100000 01101000 01100001 01110011 01110100 00100000 01000100 01110101 00100000 01100001 01110101 01100110 00100000 01101010 01100101 01100100 01100101 01101110 00100000 01000110 01100001 01101100 01101100 00100000 01100101 01110010 01101000 01101111 01100101 01101000 01110100 00101110 00100000 01000101 01101001 01101110 01100101 01101110 00100000 01110011 01100011 01101000 01101111 01100101 01101110 01100101 01101110 00100000 01010100 01100001 01100111 00100000 01101110 01101111 01100011 01101000 00101110 00100000 01000011 01100001 01110010 01110011 01110100 01100101 01101110
Ich hab mir mal erlaubt, das Ganze etwas zu formatieren, damit es auch in den Kommentar rein passt. Und ja, es gibt keine wirklich sinnvolle Anwendung dafür, zumindest nicht auf Webseite. Mir fällt zumindest auch keine ein. Und ja, es war genau meine Absicht, den Geek-Faktor etwas zu erhöhen :-)
Wir haben es in der Schule letzten Monat gelernt. Ist nicht so schwer wie immer gesagt wird und es macht sogar Spaß, einige Sachen umzurechnen. Mit PHP ist es natürlich noch schneller =)
Danke für den Code.