Little endian to big endian UTF-16 conversion

Any IBM i topic that does not fit in another forum
Post Reply
peder udesen
Posts: 22
Joined: Thu Jul 29, 2021 8:00 am

Little endian to big endian UTF-16 conversion

Post 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
Scott Klement
Site Admin
Posts: 872
Joined: Sun Jul 04, 2021 5:12 am

Re: Little endian to big endian UTF-16 conversion

Post 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
Post Reply