I am not getting proper method to convert string "Email addresses always uses @ sign" to UTF 16 code And also want to know Is it same as that of ASCII code?
Asked
Active
Viewed 578 times
-1
-
UTF-16BE or UTF-16LE? – Ignacio Vazquez-Abrams Sep 29 '13 at 07:16
-
It is pretty unclear what you are asking. Do you wish to encode that string using UTF-16? If so, little endian or big endian? (Note "encode" is a more proper term than "convert" in this case.) – Ray Toal Sep 29 '13 at 07:16
1 Answers
0
Use the command line.
If you don't care about endianness, you'll get a BOM:
$ echo "Email addresses always use the @ sign" | iconv -t utf-16 | hexdump
0000000 fe ff 00 45 00 6d 00 61 00 69 00 6c 00 20 00 61
0000010 00 64 00 64 00 72 00 65 00 73 00 73 00 65 00 73
0000020 00 20 00 61 00 6c 00 77 00 61 00 79 00 73 00 20
0000030 00 75 00 73 00 65 00 20 00 74 00 68 00 65 00 20
0000040 00 40 00 20 00 73 00 69 00 67 00 6e 00 0a
000004e
Here's big endian:
$ echo "Email addresses always use the @ sign" | iconv -t utf-16be | hexdump
0000000 00 45 00 6d 00 61 00 69 00 6c 00 20 00 61 00 64
0000010 00 64 00 72 00 65 00 73 00 73 00 65 00 73 00 20
0000020 00 61 00 6c 00 77 00 61 00 79 00 73 00 20 00 75
0000030 00 73 00 65 00 20 00 74 00 68 00 65 00 20 00 40
0000040 00 20 00 73 00 69 00 67 00 6e 00 0a
000004c
And little endian:
$ echo "Email addresses always use the @ sign" | iconv -t utf-16le | hexdump
0000000 45 00 6d 00 61 00 69 00 6c 00 20 00 61 00 64 00
0000010 64 00 72 00 65 00 73 00 73 00 65 00 73 00 20 00
0000020 61 00 6c 00 77 00 61 00 79 00 73 00 20 00 75 00
0000030 73 00 65 00 20 00 74 00 68 00 65 00 20 00 40 00
0000040 20 00 73 00 69 00 67 00 6e 00 0a 00
000004c
You should remove the newline at the end.
Oh, and no, UTF-16 is absolutely not the same encoding as ASCII.

Ray Toal
- 86,166
- 18
- 182
- 232