Page 1 of 1

Little endian to big endian UTF-16 conversion

Posted: Fri Sep 13, 2024 12:24 pm
by peder udesen
Receiving a file in UTF-16 little endian from a Windows on an as/400 ( formerly known as ) gives a practical problem
that the as/400 only can handle UTF-16 big endian ( CCSID(1200) ).
As far as I can see UTF-16 little endian ( CCSID(1202) ) is not supported here.

The question is: Is it enough to create a program that reads 2 bytes from the UTF-16LE file, swaps the bytes and writes
the 2 bytes to a file that then should be in UTF-16BE format. Of course reading and writing if pure binary.

Something like this in pseudo code

Code: Select all

open UTF-16LE input  binary mode
open UTF-16BE output binary mode 

read 2bytes from UTF-16LE
dow not eof(UTF-16LE)
  swap(2bytes) 
  write 2bytes to UTF-16BE
  
  read 2bytes from UTF-16LE
enddo

close UTF-16LE 
close UTF-16BE 
And then finally change the CCSID on UTF-16BE to 1200

Re: Little endian to big endian UTF-16 conversion

Posted: Fri Sep 13, 2024 4:56 pm
by Scott Klement
That sounds correct to me. It should work.

There is also the "Transform UCS Data" API that could potentially be used. https://www.ibm.com/docs/api/v1/content ... gtrans.htm