How to convert UTF-16 to ASCII

I am writing a subroutine in MIPS assembly language for converting ASCII to UTF-16 and vice versa. However, I could not find any trick how to convert it.

Thanks for any ideas.

+5
source share
3 answers

Pseudocode, assuming your bytes are octets and that zero termination is not required:

Convert from ASCII to UTF-16

  • Given an ASCII input string of length n (in bytes), stored sequentially in memory at address p.
  • Allocate 2 × n bytes of memory; let the starting address of this memory is q.
  • While n is greater than zero:
    • , p ASCII. , , . , .
    • p 16- q. , ; , x86 MOVZX. .
    • p 1.
    • q 2.
    • n 1.

UTF-16 ASCII

  • UTF-16 n ( ), p.
  • n ; q.
  • n :
    • , 16- p ASCII. , ASCII. , .
    • 16- p q.
    • q.
    • p 2.
    • q 1.
    • n 1.
+6

UCS2 ( 16- ), ASCII, short <-> char -, , 128.

+1

ASCII .

ISO-646 Unicode UTF-16. , "7-" ASCII Unicode (.. 16- ), , , 8 Unicode, ASCII, , .

, , ISO-8859-1 (Latin-1), . , , .

+1

All Articles