Application icon

Working With Binary Files

While not really designed to manipulate the content of binary files, you can do so ... if you're careful.

Yate can read the content of any file using the Read Text File statement with the encoding set to Latin-1. As Latin-1 supports 256 characters, every byte of data in a file can be represented. After reading a file with the Latin-1 encoding, every character in the destination variable will contain a single byte of data in each character. Every character will have a character value of 0 through 255.

In order to get the value of a character, you must position the character to be the first in a string and then convert the value to text. eg.

 1: ' Read a file as binary
 2: Prompt for File. Save path to named variable 'input path'
 3: Read Text File "\<input path>" into named variable 'content' using encoding Latin-1
 4: 
 5: ' Get the numeric value of the 3rd byte in the file into named variable 'byte'
 6: Integer value of Unicode character at index '2' of named variable 'content' -> named variable 'byte'

Statement 6 is a Substring statement.

To get a character suitable to insert in the binary data, you have to do the reverse. eg.

1: ' Get a character with the value of 255
2: Set named variable 'byte' to "255"
3: Format named variable 'Character' as Unicode character from number, save to named variable 'byte'

Statement 3 is a Format Numeric statement.

Lists of numbers can be converted by using the List Numeric Functions statement with the Unicode String option.

 1: ' Insert binary 1 through 5 after the third character in a string
 2: Set named variable 'bytes' to "1,2,3,4,5"
 3: Create String from Unicode Values of the list in named variable 'bytes' with delimiter ",". Result to named variable 'bytes'
 4: Insert "\<bytes>" at index "3" from the beginning in named variable 'content'

Statement 4 is a Remove/Insert statement.


To write a binary file, use the Write Text File statement with an encoding of Latin-1. eg:

1: Write Text File "\<input path>" from named variable 'content', encoding Latin-1 (Lossless)