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

Reply via email to