WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

How To
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Convert Unicode to Big Endian


Keyword: Convert Unicode Big Endian BinaryPeekHex  BinaryPokeHex 

Question:

I'm extracting an textfile out of an pdf for using it as an online help on an PowerPC. For displaying this text on PowerPC directly, i need an text file in Unicode Big Endian format.

I want to create file i can use on PowerPC but the only options to write this file are Ansi and Unicode. And this Unicode writing generates an Unicode Little Endian format.

Help.

Answer:

input = 'c:\temp\Unicode.txt'
size = FileSize(input)

;Allocate two seperate binary buffers
buffer1 = BinaryAlloc(size)
buffer2 = BinaryAlloc(size)

;Initialize buffer with data
BinaryRead( buffer1, input )

;Loop through file two bytes at a time
For x = 0 To size-2 By 2
   ;Read out 2 hex bytes at a time
   bytes1 = BinaryPeekHex(buffer1, x, 1)
   bytes2 = BinaryPeekHex(buffer1, x+1, 1 )

   ;Write out swapped hex bytes
   BinaryPokeHex(buffer2, x, bytes2)
   BinaryPokeHex(buffer2, X+1, bytes1)
Next

BinaryWrite( buffer2, 'C:\temp\BigEndian.txt' )

;Free Binary Buffers
BinaryFree(buffer1)
BinaryFree(buffer2)

Article ID:   W17917
Filename:   Convert Unicode to Big Endian.txt
File Created: 2008:11:25:11:59:00
Last Updated: 2008:11:25:11:59:00