<script> function binary_encode( s ){ s = unescape( encodeURIComponent( s ) ); var chr, i = 0, l = s.length, out = ''; for( ; i < l; i ++ ){ chr = s.charCodeAt( i ).toString( 2 ); while( chr.length % 8 != 0 ){ chr = '0' + chr; } out += chr; } return out; } var prueba = binary_encode('hola'); alert(prueba); </script>