Since URLs often contain characters outside the ASCII set, the URL has to be converted into a valid ASCII format. Show URL encoding replaces unsafe ASCII characters with a "%" followed by two hexadecimal digits. URLs cannot contain spaces. URL encoding normally replaces a space with a plus (+) sign or with %20. Try It YourselfIf you click the "Submit" button below, the browser will URL encode the input before it is sent to the server. A page at the server will display the received input. Base64 is a group of similar binary-to-text encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation. The term Base64 originates from a specific . Base64 encoding schemes are commonly used when there is a need to encode binary data that needs to be stored and transferred over media that are designed to deal with ASCII. This is to ensure that the data remain intact without modification during transport. Base64 is commonly used in a number of applications including email via MIME, and storing complex data in XML. One common application of Base64 encoding on the web is to encode binary data so it can be included in a data: URL. In JavaScript there are two functions respectively for decoding and encoding Base64 strings:
The algorithm used by Note: Each Base64 digit represents exactly 6 bits of data. So, three 8-bits bytes of the input string/binary file (3×8 bits = 24 bits) can be represented by four 6-bit Base64 digits (4×6 = 24 bits). This means that the Base64 version of a string or file will be at least 133% the size of its source (a ~33% increase). The increase may be larger if the encoded data is small. For example, the string 0 with 1 gets encoded to 2 with 3 — a 300% increase.Since JavaScript strings are 16-bit-encoded strings, in most browsers calling 4 on a Unicode string will cause a 5 exception if a character exceeds the range of a 8-bit ASCII-encoded character. There are two possible methods to solve this problem:
Here are the two possible methods.
This solution has been proposed by Johan Sundström. Another possible solution without utilizing the now deprecated 'unescape' and 'escape' functions. This alternative, though, does not perform base64 encoding of the input string. Note the differences in the outputs of 6 and 7. Adopting this alternative may lead to interoperability issues with other applications.
Note: The following code is also useful to get an ArrayBuffer from a Base64 string and/or vice versa ().
These function let us to create also uint8Arrays or arrayBuffers from Base64-encoded strings:
Note: The function 1 returns an 2 of bytes. If your aim is to build a buffer of 16-bit / 32-bit / 64-bit raw data, use the 3 argument, which is the number of bytes of which the 4 property must result a multiple ( 5 or omitted for ASCII, binary strings (i.e., a string in which each character in the string is treated as a byte of binary data) or UTF-8-encoded strings, 6 for UTF-16 strings, 7 for UTF-32 strings).
Jelaskan apa yang dimaksud dengan encoding dan decoding?Dalam dunia komputer, encode adalah proses penempatan urutan karakter (huruf, angka, tanda baca, dan symbol tertentu) ke dalam format khusus sehingga menjadi sebuah sandi. Sedangkan decode adalah proses sebaliknya yaitu konversi dari format yang disandikan kembali pada karakter asli.
Apa yang dimaksud dengan decoding dalam komunikasi?Sedangkan decoding merupakan kegiatan menerima dan memahami pesan seperti mendengarkan dan membaca. Pesan adalah apa yang dikomunikasikan oleh sumber kepada penerima. Pesan merupakan seperangkat simbol verbal maupun nonverbal yang berisi ide, sikap dan nilai komunikator.
|