Another method as done in tara would be using 3!:4 and 3&u: to convert to machine endian utf16, and then swap byte pair if needed.

Fred Bone wrote:
I said:

[...]
These two verbs should take a string of Unicode widechars and emit bytes
in UTF-16.

utf16be =. [:,a.{~256#.(^:_1)3 u:]
utf16le =. [:,[:|."1 a.{~256(#.^:_1)3 u:]

Scrub that: these only work for characters over U+00ff.

Try these instead:
   utf16be =. [:,a.{~[:}.256#.(^:_1)999,3 u:]
   utf16le =. [:,[:|."1 a.{~[:}.256#.(^:_1)999,3 u:]

   a.i.utf16le 'hello there'
104 0 101 0 108 0 108 0 111 0 32 0 116 0 104 0 101 0 114 0 101 0
   a.i.utf16be 'hello there'
0 104 0 101 0 108 0 108 0 111 0 32 0 116 0 104 0 101 0 114 0 101

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm



--
regards,
bill
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to